C++ PROGRAM 02 FOR MECHANICAL
2. Find the smallest and largest number from given three values. ( Nested IF-ELSE Statement)
/*Program for finding largest number*/
# include <stdio.h>
main()
{
float a, b, c;
printf(" Enter the values\n");
scanf("%f%f%f", &a, &b, &c);
if(a>b)
{
if(a>c)
printf("The largest value is %7.3f", a);
else
printf("The largest value is %7.3f", c);
}
else
{
if(b>c)
printf("The largest value is %7.3f", b);
else
printf("The largest value is %7.3f", c);
}
return 0;
}
/*Program for finding smallest number*/
# include <stdio.h>
main()
{
float a, b, c;
printf(" Enter the values\n");
scanf("%f%f%f", &a, &b, &c);
if(a<b)
{
if(a<c)
printf("The smallest value is %7.3f", a);
else
printf("The smallest value is %7.3f", c);
}
else
{
if(b<c)
printf("The smallest value is %7.3f", b);
else
printf("The smallest value is %7.3f", c);
}
return 0;
}
/*Program for finding largest number*/
# include <stdio.h>
main()
{
float a, b, c;
printf(" Enter the values\n");
scanf("%f%f%f", &a, &b, &c);
if(a>b)
{
if(a>c)
printf("The largest value is %7.3f", a);
else
printf("The largest value is %7.3f", c);
}
else
{
if(b>c)
printf("The largest value is %7.3f", b);
else
printf("The largest value is %7.3f", c);
}
return 0;
}
/*Program for finding smallest number*/
# include <stdio.h>
main()
{
float a, b, c;
printf(" Enter the values\n");
scanf("%f%f%f", &a, &b, &c);
if(a<b)
{
if(a<c)
printf("The smallest value is %7.3f", a);
else
printf("The smallest value is %7.3f", c);
}
else
{
if(b<c)
printf("The smallest value is %7.3f", b);
else
printf("The smallest value is %7.3f", c);
}
return 0;
}
Comments
Post a Comment