scanff gradesi end of for printfThe Average of grade is 2fn averagegrades n

Scanff gradesi end of for printfthe average of grade

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
Image of page 5
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[0] ; 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
Image of page 6
{ if ( arr[j] > big ) big = arr[j] ; } // end of for loop return (big) ;  //returning the maximum value
Image of page 7
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