Practical 2B- Formatting output and selection

Posted: January 20, 2012 in Lab 3

Problem Statement-
A student sits three examinations:
• He is awarded a pass if he scores at least 50 in each of the examinations.
• He is awarded a pass by compensation in all three examinations if he passes in
two and the average of the three marks is at least 40.
• He fails if neither of the above hold.
Write a program which takes the three marks as input and outputs the message
indicating either a PASS, a PASS by COMPENSATION or a FAIL.
Example 1:
Result Classification
——————————-
Enter the first mark: 34
Enter the second mark: 50
Enter the third mark: 51
PASS BY COMPENSATION
Example 2:
Result Classification
——————————-
Enter the first mark: 50
Enter the second mark: 67
Enter the third mark: 58
PASS

#include<stdio.h>
int marks(int *);
int main()
{
	int m[3];
	printf("Result Classification\n");
	printf("------------------------\n");
	printf("Enter the first mark: ");
	scanf("%d",&m[0]);
	printf("Enter the second mark: ");
	scanf("%d",&m[1]);
	printf("Enter the third mark: ");
	scanf("%d",&m[2]);
      marks(&m[0]);
	return 0;
}
int marks(int *a)
{
	if(*(a+0)>=50&&*(a+1)>=50&&*(a+2)>=50)
	{
		printf("PASS\n");
	}
	else
		if((*(a+0)>=50&&*(a+1)>=50&&*(a+2)<50)||(*(a+0)>=50&&*(a+1)<50&&*(a+2)>=50)||(*(a+0)<50&&*(a+1)>=50&&*(a+2)>=50))
		if(((*(a+0)+*(a+1)+*(a+2))/3)>=40)
			printf("PASS BY COMPENSATION\n");
	else
			printf("FAIL\n");
	return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s