C program that inputs a student’s marks in three subjects.

Q4. Write a C program that inputs a student’s marks in three subjects (out of 100) and prints the percentage marks.

Ans.

#include<stdio.h>

#include<conio.h>  //for clrscr()

int main()

{

float sub1,sub2,sub3,marks,perc;

clrscr();   //for clear screen

printf(“Enter marks obtained in 3 subjects:”);

scanf(“%f %f %f”,&sub1,&sub2,&sub3);

marks=sub1+sub2+sub3;

perc=(marks/300)*100;

printf(“\n The percentage marks are: %f%”,perc);

return 0;

}

 

Output

Enter marks obtained in 3 subjects:69 89 78

The percentage marks are:78.666664%

Leave a Reply

Your email address will not be published. Required fields are marked *

89 Views
%d bloggers like this: