Jan 12, 2020

C program to accept students marks and display result

Ex: write a C program to accept students marks and display result. hoe to write a C program to accept students marks and display result. C prgram to accept students
marks and display result.

Input from user:
Enter the three subjects marks:
65
77
88

Expected output:
Total marks = 230
Average marks = 76.0000
Result is distinction.




Step by step logic of program to display result:

1. First declare intiger variable's  s1, s2, s3 for three subjects marks and total to 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. After that use  given conditions using if-else statement's to print result.

5. if(average>=70)
print result is distinction.

6. if(average>=60)
print result is first class.

7. if(average>=50)
print result is second class.

8. if(average>=40)
print result is pass.

9. Otherwise print result is fail.







Program:


#include<stdio.h>
void main()
{

 int s1,s2,s3,total;
 float average;

 printf("Enter the three subjects marks one by one:\n");
scanf("%d%d%d",&s1,&s2,&s3);

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

   printf("\nTotal marks= %d",total);
 printf("\nAverage marks= %f\n",average);

 if(average>=70)
  {
   printf("Result is distinction\n"); 
  }
 else if(average>=60)
  {    
   printf("Result is first class\n"); 
  }
 else if(average>=50)
  {
   printf("Result is second class\n");
   }
  else if(average>=40 )
    {
    printf("Result is pass \n");  
    }
    else
    {
    printf("Result is Fail\n");
    }

}


Above program shows the following output:





Share This:    Facebook Twitter

0 comments:

Post a Comment

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