Saturday, April 11, 2009

Calculate percentage of 5 subjects & display Divison resp.

/*The marks obtained by a student in 5 different subjects are input through keyboard.The student gets a division as per the following rules:

Percentage above or equal to 60 - First division
Per btw 50 and 59 - Second div
per btw 40 and 49-Third div
per less than 40 - Fail */

Solution Code:
=========

#include <stdio.h>
int main(void)
{
int m1,m2,m3,m4,m5,sum,per;
printf("Enter marks for Math : ");
scanf("%d",&m1);
printf("\nEnter marks for Chemistry : ");
scanf("%d",&m2);
printf("\nEnter marks for Biology : ");
scanf("%d",&m3);
printf("\nEnter marks for Physics : ");
scanf("%d",&m4);
printf("\nEnter marks for English : ");
scanf("%d",&m5);
sum = (m1 + m2 + m3 + m4 + m5);
per = (sum * 100 / 500);
printf("\nYou got %d percentage",per);

if ( per >= 60 )
printf("\nFirst Division");

else if (( per <= 59) && ( per >= 50 ))
printf("\nSecond Divison");

else if (( per <= 49 ) && ( per >= 40 ))
printf("\nThird Divison");

else
printf("\nSorry you Failed");
return 0;
}

2nd Solution Code:-
===========

#include
int main(void)
{
int m1,m2,m3,m4,m5,sum,per;
printf("Enter marks for Math : ");
scanf("%d",&m1);
printf("\nEnter marks for Chemistry : ");
scanf("%d",&m2);
printf("\nEnter marks for Biology : ");
scanf("%d",&m3);
printf("\nEnter marks for Physics : ");
scanf("%d",&m4);
printf("\nEnter marks for English : ");
scanf("%d",&m5);
sum = (m1 + m2 + m3 + m4 + m5);
per = (sum * 100 / 500);
printf("\nYou got %d percentage",per);

if ( per >= 60 )
printf("\nFirst Division");
else
{
if ( per >= 50 )
printf("\nSecond Division");

else
{
if ( per >= 40 )
printf("\nThird Division");

else
printf("\nFail");
}
}
return 0;
}


No comments: