$25
Write two C programs that performs the task described belowTask
1. Write the reverse string() function for the given code below.
(Hint: use strlen() function which gives the length of a string.)
#include<stdio.h #include<string.h void reverse_string(char str[]);
int main(){ char str_arr[100];
printf("Enter a string:"); scanf("%s", str_arr); reverse_string(str_arr);
printf("Reversed string is: %s \n", str_arr);
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1
2. Write print line(), print histogram() and len() functions for the given code below. printline() : Prints <int num of chars times <char c character. print histogram() : Prints a histogram of <int values[] with <char c using print print line() and len() functions. len() : Returns the length of <int array[].
#include<stdio.h void print_line(char c, int num_of_chars); void print_histogram(char c, int vals[]); int len(int arr[]);
int main(){ int values[100], val=1, count=0; printf("Enter positive integer(s), to print an
histogram.\nEnter a non-positive integer to stop.\n\n"); do{ printf("Enter a value:"); scanf("%d", &val); values[count] = val; count++; }while(val 0); print_histogram(’*’, values); return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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: ***
*****
******
**