By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Highest and lowest number in one structure

P: 2
what I'm gonna do in my problem program? Can you help me in that one?
Create a program that you have input 5 numbers and in the output will identify the highest and lowest number. Seletion structure in turbo c++
Dec 11 '15 #1
Share this Question
Share on Google+
3 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
First write a program the lets you enter five numbers and display them.

Get that working then add the logic to find the smallest/largest number.

Post some code so I can see hoe you are doing.
Dec 12 '15 #2

P: 2
Expand|Select|Wrap|Line Numbers
  1. main ()
  2.  
  3. {
  4. int a,b,c,d,e;
  5. clrscr();
  6. p("Enter a number: ");
  7. scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
  8. if ( a<b && a<c && a<d && a<e )
  9. p("Lowest number: %d\n",a);
  10. else if (a>b && b>c && c>d && d>e )
  11. p("Highest number: %d\n",a);
  12. else if ( b<a && b<c && b<d && d<e )
  13. p("Lowest number: %d\n",b);
  14. else if ( b>a && b>c && b>d && b>e )
  15. p("Highest number: %d\n",b);
  16. else if ( c<a && c<b && c<d && c<e )
  17. p("Lowest number: %d\n",c);
  18. else if (c>a && c>b && c>d && c>e )
  19. p("Highest number: %d\n",c);
  20. else if ( d<a && d<b && d<c && d<e )
  21. p("Lowest number: %d\n",d);
  22. else if ( d>a && d>b && d>c && d>e )
  23. p("Highest number: %d\n",d);
  24. else if ( e>a && e>b && e>c && e>d )
  25. p("Lowest number: %d\n",e);
  26. else if ( e<a && e<b && e<c && e<d );
  27. p("Highest number: %d\n",e);
  28.  
can you checked,what's wrong on my code?
Dec 13 '15 #3

P: 16
Why dont you assume one value, say a, as highest and an other, maybe e, as the lowest and check each value(b,c,d,e and a,b,c,d) one by one against the assumed values. This logic should reduce the number of comparisons required. It'll look a lot cleaner too.
Dec 13 '15 #4

Post your reply

Sign in to post your reply or Sign up for a free account.