end of max function Sample Output Solved Problem5 write a function that

End of max function sample output solved problem5

This preview shows page 7 - 8 out of 8 pages.

//end of max function Sample Output: Solved Problem#5 : write a function that receives a 1-D array of real values and reverses it. #include <stdio.h> #define SIZE 40 void reverse (double array[], int n) { int i; double temp; for (i=0;i<n/2;i++) { temp=array[i]; array[i]=array[n-1-i]; array[n-1-i]=temp; } } int main() { double x[SIZE]; int n,i; printf ("enter number of values to read\n"); scanf("%d",&n); printf("enter %d values separated by space\n",n); for (i=0;i<n;i++) scanf("%lf",&x[i]); printf("elements of the array before reversal\n"); for (i=0;i<n;i++) printf("x[%d]=%f\n",i,x[i]); reverse(x,n); ICS 103 : Computer Programming in C , Term-032 ; Rafiq Khan Page 7 of 8
Image of page 7
printf("elements of the array after reversal\n"); for (i=0;i<n;i++) printf("x[%d]=%f\n",i,x[i]); return 0; } Solved Problem#6 : Write a function that receives a 1-D array of integer values. It then returns the maximum and the minimum through the output parameter. #include <stdio.h> #define SIZE 40 void maxmin (int array[], int n, int *min, int *max) { int i; *max=*min=array[0]; // initialize max and *min with first element of the array for (i=1;i<n;i++) { if(*max<array[i]) *max=array[i]; else if (*min > array[i]) *min=array[i]; } } int main() { int x[SIZE]; int n,i,min,max; printf ("enter number of values to read\n"); scanf("%d",&n); printf("enter %d values separated by space\n",n); for (i=0;i<n;i++) scanf("%d",&x[i]); maxmin(x,n,&min,&max); printf("maximum=%d\nminimum=%d\n",max,min); return 0; } ICS 103 : Computer Programming in C , Term-032 ; Rafiq Khan Page 8 of 8
Image of page 8

You've reached the end of your free preview.

Want to read all 8 pages?

  • Spring '10
  • zaman
  • Array, Subroutine, #define, Even and odd functions

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes