Explanation: This program accepts the marks of four subjects from the user, calculates the total and average marks, and then checks whether the student has passed or failed using the if-else statement.
#include <stdio.h> #include <conio.h> main() { int a,b,c,d,total,avg; clrscr(); printf("Enter Marks of Subject 1 : "); scanf("%d",&a); printf("Enter Marks of Subject 2 : "); scanf("%d",&b); printf("Enter Marks of Subject 3 : "); scanf("%d",&c); printf("Enter Marks of Subject 4 : "); scanf("%d",&d); total = a + b + c + d; avg = total / 4; printf("\nTotal Marks = %d",total); printf("\nAverage Marks = %d",avg); if(avg >= 35) { printf("\nStudent is Pass"); } else { printf("\nStudent is Fail"); } getch(); }
Output:
if-else statement to determine the result.Average = Total / 5 and check whether the average is greater than or equal to 40.
#include <stdio.h> #include <conio.h> main() { int m1,m2,m3,m4,m5,total,avg; clrscr(); printf("Enter Marks of Subject 1 : "); scanf("%d",&m1); printf("Enter Marks of Subject 2 : "); scanf("%d",&m2); printf("Enter Marks of Subject 3 : "); scanf("%d",&m3); printf("Enter Marks of Subject 4 : "); scanf("%d",&m4); printf("Enter Marks of Subject 5 : "); scanf("%d",&m5); total = m1 + m2 + m3 + m4 + m5; avg = total / 5; printf("\nTotal Marks = %d",total); printf("\nAverage Marks = %d",avg); if(avg >= 40) { printf("\nStudent is Pass"); } else { printf("\nStudent is Fail"); } getch(); }
if-else statement to determine whether the student has passed or failed based on the average marks.