In this example, the if-else-if ladder takes decision based on the value of percentage of marks (percentage) calculated and displays the appropriate division. Here, the value of the percentage calculated for inputted data 80 50 75 evaluates to be 68.33. On the basis of this value, the first condition in if-else-if ladder (percentage>=60 & percentage<100) which evaluates to be true so it displays the message First Division and skip the remaining conditions.
Problem Statement:
Annual exam result is to be conducted for 20 students for 3 subjects. Write a program to read the data and determine the following:
• Collect the exam result data for individual student.
• Calculate all the obtained marks from three subjects for each student.
• Put them in condition statement and get the grading and percentage of students.
• The Student who get clear the required condition for Division placement.
Here is the C program to Find the Percentage or marks of students. This C program is an example to use Control statements.
#include<stdio.h>
void main()
{
int m1,m2,m3,total;
float per;
clrscr();
printf("Enter 3 Nos.");
scanf("%D%D%D",&m1,&m2,&m3);
total=m1+m2+m3;
per=total*100/300;
if(per>=60&&per<=100)
printf("You are 1st :");
else if(per>=50&&per<=60)
printf("You are 2nd");
else if(per>=40&&per<=50)
printf("You are 3rd");
else
printf("You are Fail");
getch();
}