C Programming

Using Functions to Calculate Grade and Total Marks

Same implementation of Grade , Total marks program using Functions.

Language : C

[sourcecode language='c']
//Functions
#include
#include

float marks(); //prototype marks()
void grade(float avg); //prototype grade()

void main()
{ float avg;

avg=marks(); //Funtion calls
grade(avg);

}

float marks() //Function definition
{ int marks1,marks2,marks3,marks4,marks5,tmarks;
float avg;
char grade;

printf(“\nEnter the Marks of Subject1 : “);
scanf(“%d”, &marks1);
printf(“\nEnter the Marks of Subject2 : “);
scanf(“%d”, &marks2);
printf(“\nEnter the Marks of Subject3 : “);
scanf(“%d”, &marks3);
printf(“\nEnter the Marks of Subject4 : “);
scanf(“%d”, &marks4);
printf(“\nEnter the Marks of Subject5 : “);
scanf(“%d”, &marks5);

tmarks=marks1+marks2+marks3+marks4+marks5;
avg=tmarks/5;

printf(“\nTotal marks are : %d”, tmarks);
printf(“\n The average is : %f”, avg);

return (avg);
}

void grade(float avg) //Function definition
{
if((avg>90)&&(avg>=80))
printf(“\nGrade is A!”);
else if((avg>80)&&(avg>=70))
printf(“\nGrade is B!”);
else if((avg>70)&&(avg>=60))
printf(“\nGrade is C!”);
else if((avg>=60)&&(avg>=50))
printf(“\nGrade is D!”);
else if((avg>50)&&(avg>=40))
printf(“\nGrade is E!”);
else
printf(“\nGrade is F!”);

}

[/sourcecode]



Leave a Comment

Notify me of followup comments via e-mail. You can also subscribe without commenting.


WordPress - Vaibhav Kanwal