The program segment given below accepts marks in a single subject and uses a nested if statement to determine the validity of marks and the result if the value of marks is valid. This code can be written in a more readable form using an if-else-if statement as
#include <stdio.h>
void main()
{
int marks;
clrscr();
printf(“Enter Marks of single subject :\n”);
scanf (“%d”, &marks);
if (marks >= 0)
{
if (marks <= 100)
{
if (marks >= 35)
printf(“Result: Pass\n”);
else printf(“Result: Fail\n”);
}
else printf(“Error: Marks can’t exceed 100\n”);
}
else printf(“Error: Marks can’t be negative\n”);
getch();
}