Thursday, January 26, 2012

Program with Logical Operator

Exercise 16

The marks of five subjects of a particular student is inputted through the keyboard by the user. The division, which the student received will be prompted by the system as per following rules:

Percentage greater than or equal to 60 – First Division

Percentage less than 60 and greater than equal to 50 – Second Division

Percentage less than 50 and greater than equal to 40 – Third Division

Percentage less than 40 – Fail

Solution:
/* Program to find the Division of Marks obtained */
#include<stdio.h>
#include<conio.h>



void main()
{
int m1,m2,m3,m4,m5,p;
printf(“Enter the marks of 5 subjects ”);
scanf(“%d %d %d %d %d”, &m1,&m2,&m3,&m4,&m5);
p=(m1+m2+m3+m4+m5)/5;
if (p>=)
  printf(“First Division”);
if(p<60 && p>=50)
  printf(“Second Division”);
if(p<50 && p>=40)
  printf(“Third Division”);
if(p<40)
  printf(“Fail”);
getch();
}
Explanation: In this program we have seen the use of logical operator AND, for that we used individual if statement, for particular limits as per the demand of the program. This program can also be done with the use of nested if-else statement. But for using logical operator, we should keep in mind that while writing the program, there should not be any gap in setting up the limits in conditional structure.
Output of the program is as follows:
Case-I
Enter the marks of 5 subjects 75 65 68 72 50
First Division
Case-II
Enter the marks of 5 subjects 55 57 53 60 50
Second Division
Case-III
Enter the marks of 5 subjects 45 48 54 34 40
Third Division
Case-IV
Enter the marks of 5 subjects 35 38 24 54 30
Fail

No comments:

Post a Comment

Please give your valuable comments or queries if you fell its helpful or if you like the contents of the site. Thanks...