The example how to calculate Average Using C programming:
Example the question ask you to display the average of mark key in by the user/student and based on the input display the grade, and the average mark :-
average grade
At least 80 A
60 – 79 B
50 – 59 C
Less than 50 F
Source Code:
#include <stdio.h>
int main(){
int i;
float num[3],
sum=0.0,average;
printf("--------------------------\n ");
printf(" STUDENT DETAILS \n");
printf("--------------------------- \n\n");
for(i=0; i<3 ; i++)
{
printf("Enter mark: %d :",i+1);
scanf("%f",&num[i]);
sum+=num[i]; }
average=sum/3;
printf("\nAverage = %.2f",average);
if(average >= 80)
{
printf("\nGrade = A\n");
}
else if(average >= 60 && average <= 79)
{
printf("\nGrade = B\n");
}
else if(average >=50 && average <=59)
{
printf("\nGrade = C\n");
}
else
{
printf("\nGrade = F\n");
}
return 0;
}
Example the question ask you to display the average of mark key in by the user/student and based on the input display the grade, and the average mark :-
average grade
At least 80 A
60 – 79 B
50 – 59 C
Less than 50 F
Source Code:
#include <stdio.h>
int main(){
int i;
float num[3],
sum=0.0,average;
printf("--------------------------\n ");
printf(" STUDENT DETAILS \n");
printf("--------------------------- \n\n");
for(i=0; i<3 ; i++)
{
printf("Enter mark: %d :",i+1);
scanf("%f",&num[i]);
sum+=num[i]; }
average=sum/3;
printf("\nAverage = %.2f",average);
if(average >= 80)
{
printf("\nGrade = A\n");
}
else if(average >= 60 && average <= 79)
{
printf("\nGrade = B\n");
}
else if(average >=50 && average <=59)
{
printf("\nGrade = C\n");
}
else
{
printf("\nGrade = F\n");
}
return 0;
}
0 comments:
Post a Comment