CSE107 – Lab10 Task

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment

Description

5/5 - (3 votes)

Write two C programs that performs the task described below. Name your
c files as nameSurnameId questionNo.c [ex: basakKarakas1850044026 1.c and
basakKarakas1850044026 2.c]
Upload your file to your section’s submission page on moodle.
1 Task
1. Write the reverse string() function for the given code below.
(Hint: use strlen() function which gives the length of a string.)
1 # include < stdio .h >
2 # include < string .h >
3
4 void reverse_string ( char str []) ;
5
6 int main () {
7 char str_arr [100];
8
9 printf (” Enter a string :”);
10 scanf (“%s”, str_arr );
11 reverse_string ( str_arr );
12 printf (” Reversed string is: %s \n”, str_arr );
13
14 return 0;
15 }
16
1
2. Write print line(), print histogram() and len() functions for the given code
below.
print line() : Prints times character.
print histogram() : Prints a histogram of with using print print line() and len() functions.
len() : Returns the length of .
1 # include < stdio .h >
2
3 void print_line ( char c , int num_of_chars );
4
5 void print_histogram ( char c , int vals []) ;
6
7 int len ( int arr []) ;
8
9 int main () {
10 int values [100] , val =1 , count =0;
11 printf (” Enter positive integer (s), to print an
histogram .\ nEnter a non – positive integer to stop .\n\n”);
12 do{
13 printf (” Enter a value :”);
14 scanf (“%d”, & val ) ;
15 values [ count ] = val ;
16 count ++;
17 } while ( val > 0) ;
18 print_histogram (’*’, values );
19 return 0;
20 }
21
Sample:
Enter positive integer(s), to print an histogram.
Enter a non-positive integer to stop.
Enter a value: 3
Enter a value: 5
Enter a value: 6
Enter a value: 2
Enter a value: -1
Output:
***
*****
******
**
Good luck 🙂
2