Friday, September 5, 2014

display the greatest, medium and smallest number using the notation a,b, and c.


Problem

We will read in three integers: a, b and c. We want to construct the logic so that, no matter how these numbers were provided by the user, the output will always be the three numbers printed in order. For example, if we read in 40, 20, 60 into a, b and c respectively, then our logic would printb, a and c in that order. This will give an output of 20, 40 and 60. Or if we read in 70, 10 and 60, then the output would be b, c and a in that order. This will give an output of 10, 60 and 70.

Solution - Code

#include<stdio.h>
main()
{
 int a,b,c;
 printf("Enter 1st Value");
 scanf("%d",&a);

 printf("Enter 1st Value");
 scanf("%d",&b);

 printf("Enter 1st Value");
 scanf("%d",&c);


 if(a<b && a<c)
  printf("a");
 else if(b<a && b<c)
  printf("b");
 else
  printf("c");

 if(a<b && a>c || a>b && a<c)
  printf("a");
 else if(b<a && b>c ||b>a && b<c)
  printf("b");
 else
  printf("c");


 if(a>b && a>c)
  printf("a");
 else if(b>a && b>c)
  printf("b");
 else
  printf("c");

 system("pause");
}

Sample Output


No comments :

Post a Comment

Note: Only a member of this blog may post a comment.

Copyright 2017. All Rights Reserved. Privacy Policy / Terms And Conditions / Sitemap / Contact