Question-Write a function that receives marks received by a student in 3
subjects and returns the average and percentage of these
marks. Call this function from main( )and print the results in
main( ).
Solution-An easy question. I am following call by reference again.
#include<stdio.h>
int main()
{
int a,b,c;
float avg,percentage;
printf("Enter marks obtained in 3 subjects\n");
scanf("%d%d%d",&a,&b,&c);
stud(&a,&b,&c,&avg,&percentage);
printf("Average Marks=%f\nPercentage=%f\n",avg,percentage);
return 0;
}
stud(int *a,int *b,int *c,float *avg, float *percentage)
{
*avg=(*a+*b+*c)/3;
*percentage=*avg;
return (*avg,*percentage);
}
subjects and returns the average and percentage of these
marks. Call this function from main( )and print the results in
main( ).
Solution-An easy question. I am following call by reference again.
#include<stdio.h>
int main()
{
int a,b,c;
float avg,percentage;
printf("Enter marks obtained in 3 subjects\n");
scanf("%d%d%d",&a,&b,&c);
stud(&a,&b,&c,&avg,&percentage);
printf("Average Marks=%f\nPercentage=%f\n",avg,percentage);
return 0;
}
stud(int *a,int *b,int *c,float *avg, float *percentage)
{
*avg=(*a+*b+*c)/3;
*percentage=*avg;
return (*avg,*percentage);
}
No comments:
Post a Comment