by Dinesh Thakur Category: Control Structures

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;


    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");



         C Program Examination result in a single subject with data validation

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles