Friday, May 30, 2014

WRITE A FUNCTION TO CALCULATE THE AVERAGE OF MARKS OF STUDENT AND THEN PRINT THE RESULT IN CALLING FUNCTION

#include<stdio.h>
#include<conio.h>
typedef struct student
{
char name[20];
int rollno;
int age;
int marks[4];
}stu;
float fun1(int*);
void main()
{
stu s1;
int i;
float avg;
clrscr();
printf("enter the name, rollno and age of student\n");
scanf("%s%d%d",s1.name,&s1.rollno,&s1.age);
printf("enter the marks in 4 subjects\n");
for(i=0;i<4;i++)
{
scanf("%d",&s1.marks[i]);
}
avg=fun1(s1.marks);
printf("the average of %s is= %f",s1.name,avg);
getch();
}

float fun1(int *p)
{
int i,sum=0;
float avg;
for(i=0;i<4;i++)
{
sum=sum+*p;
p++;
}
avg=sum/4.0;
return(avg);
}

No comments:

Post a Comment