This website completely moved to new platform. For latest content, visit www.programmingposts.com

Search this Site

28 Sept 2012

C PROGRAM TO FIND THE AVERAGE OF MARKS USING FUNCTION


/** C PROGRAM TO FIND THE AVERAGE OF MARKS USING FUNCTION **/
#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 )



No comments:

Post a Comment

Thanks for your comments.
-Sameer