C PROGRAM TO FIND THE AVERAGE OF MARKS USING FUNCTION
/** C PROGRAM TO FIND THE AVERAGE OF MARKS USING FUNCTION **/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#include<stdio.h> #include<conio.h> #define MAX 100 //maximum size of array is 100 int marks[MAX]; //function declaration int CalculateAverage(int); main() { int i,n; int average; printf(">>> program to find average of marks using function <<<"); printf("\n\n Enter the Number of Subjects: "); scanf("%d",&n); //taking input from user printf("\n Enter the %d Subjects Marks: ",\n); for(i=0;i<n;i++) { printf("\n subject[%d]:",i+1); scanf("%d",&marks[i]); //taking input all the marks using for loop } average = CalculateAverage(n); //calling function printf("\n The Average Of Marks is: %d ",average); getch(); } int CalculateAverage(int no) //function body { int avg; int sum=0; int i; for(i=0;i<no;i++) { sum = sum + marks[i]; //Adding all marks to get sum } avg=sum/no; //calculating average return avg; } |
Output: ( using GNU GCC Compiler with code::blocks IDE )