Friday, January 21, 2011

Operators and Expressions

Write a program to read three values using scanf statement and print the following result;
a. Sum of the values
b. Average of the three values
c. Largest of the three
d. Smallest of three
#include<stdio.h>
void main()
{
int a,b,c,x;
float ave;
clrscr();
printf("Enter three integer values\n");
scanf("%d %d %d",&a,&b,&c);
x = a+b+c;
ave = (float)x/3;
printf("Sum of these number = %d",x);
prinf("Average of these number = %f",ave);
if(a>b)
{
if(a>c)
printf("Largest number is %d",a);
else
printf("Largest number is %d",c);
}
else
{
if(c>b)
printf("Largest number is %d\n",c);
else
printf("Largest number is %d\n",b);
}
if(a
{
if(a
printf("Smallest number is %d",a);
else
printf("Smallest number is %d",c);
}
else
{
if(c
printf("Smallest number is %d",c);
else
printf("Smallest nubmer is %d",b);
}
getch();
}

No comments:

Post a Comment