Write a c program with a main function which calls 3 functions, excercise1 thru
ID: 3913027 • Letter: W
Question
Write a c program with a main function which calls 3 functions, excercise1 thru exercise3. Those functions in turn declare local variables and call other functions; load_array, reverse_array, and change_item. Each function should return a Boolean value to the caller and be checked in the caller to in turn return a Boolean value to main where each function call is evaluated for false. If it is false it will print a message saying it is false and there is an error etc. So main will have 6 function declarations, 6 definitions, 6 function calls, and 7 returns (main returns 0). Pay attention to the function headers, how functions are called, and how arrays and or elements are passed.
Explanation / Answer
#include <stdio.h>
int main()
{
int n, c, d, a[100], b[100];
printf("Enter the number of elements in array ");
scanf("%d", &n);
printf("Enter the array elements ");
for (c = 0; c < n ; c++)
scanf("%d", &a[c]);
/*
* Copying elements into array b starting from end of array a
*/
for (c = n - 1, d = 0; c >= 0; c--, d++)
b[d] = a[c];
/*
* Copying reversed array into original.
* Here we are modifying original array, this is optional.
*/
for (c = 0; c < n; c++)
a[c] = b[c];
printf("Reverse array is ");
for (c = 0; c < n; c++)
printf("%d ", a[c]);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.