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

scanf("%f", &grades[i]);   }  // end of for   printf("The Average of grade is %.2f\n", average(grades, n)); // function call   return 0; // emd of main Sample Output: ICS 103 : Computer Programming in C , Term-032 ; Rafiq Khan Page 5 of 8 Solved Problem#4 : To pass the array to a function we write the name of the array. To declare the function that accepts an array as its parameter we write the name of the array followed by the [ ] without the size of the array in its parameter declaration part. Consider the following problem of finding the maximum of 4 integer numbers. #include <stdio.h> #define SIZE 4 // defining the size of the array as 4 . int   max (int  arr[ ] ) ;  // declaring the function max which returns integer value and accepts an                                              // integer  array called arr void main (void) { int arr [SIZE] , j , big ;  //declaring the array arr along with other variables for ( j = 0 ; j < SIZE ; ++j )  //using for loop to read the array {                     printf ("Enter the %dth element of array : ", j ) ;      scanf ( "%d", &arr[j] ) ; } // end of for big = max ( arr ) ;  //calling the function max by passing the array with only name printf ("\nThe maximum value is : %d\n", big ) ; // end of main int  max ( int arr[ ] )  //function declaring that it accepts integer array arr as its input {             int j , big = arr ; for ( j = 0 ; j < SIZE ; ++j )  //using for loop to find the maximum number of array arr ICS 103 : Computer Programming in C , Term-032 ; Rafiq Khan Page 6 of 8 { if ( arr[j] > big ) big = arr[j] ; } // end of for loop return (big) ;  //returning the maximum value  #### 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
• • •  