Jan 9, 2020

C Program to calculate total & average of three subjects marks

Ex: write a C program to calculate total and average  of three subjects marks. How to write a C program to calculate total and average of three subjects. C Program to calculate total and average of three subjects.


Input from user:

Enter three subjects marks:
75
85
65

Expected output:

Total= 225
Average= 75.0000





Step by step logic of the given program:


1. First declare intiger variable's  S1, S2, S3 for three subjects marks and total for store total marks and float type variable  average for average marks.

2. Accept three subjects marks from user using input/output function's.

3. In the logic add three subject marks and store it in variable total (total=S1+S2+S3;).
After that devide total by no. of subjects and store it in variable average (average=total/3;)

4. print total and average marks on the output screen.




Program:

#include<stdio.h>
int main()
{
 int s1,s2,s3,total;
 float average;

 printf("Enter three subject marks:\n");
scanf("%d%d%d",&s1,&s2,&s3);

 total=s1+s2+s3;
 average=total/3;

 printf("Total= %d\nAverage= %f",total,average);

return 0;
}



Above program shows the following output:






Share This:    Facebook Twitter

0 comments:

Post a Comment

If you have any doubts, please discuss here...