Sunday, February 1, 2015

CS6212 – PROGRAMMING AND DATA STRUCTURES I LAB

GREATEST OF THREE NUMBERS


AIM
            To write a C program to implement the greatest of three numbers.

ALGORITHM
Step-1: Start the program
Step-2: Read the three numbers a,b,c.
Step-3: check for the 1st two numbers.
Step-4: If a is greater than b then proceed by checking with c
Step-5: If b is greater than a then proceed by checking with c
Step-6: Display the result
Step-7: End the program

PROGRAM
void main()
{
int a,b;
printf(“\n Enter a and b values:”);
scanf(“%d %d ”,&a,&b);
if(a>b)
{
            if((a!=0) && (b!=0))
{
printf(“\na and b both are +ve and a >b);
else
printf(“\n a is greater than b only”)
}
}
else
{
printf(“ \na is less than b”);
}
}


OUTPUT
Enter a and b values: 30
20
a and b both are +ve and a > b


RESULT: Thus a c program to implement the greatest of three numbers is executed.

No comments:

Post a Comment