# Largest / Smallest (5 integers)

• 10-09-2005
Ripley
Largest / Smallest (5 integers)
Code:

```#include <stdio.h> int main() { int a,b,c,d,e; printf( "Enter number for 'a':\n" ); scanf( "%d", &a ); printf( "Enter number for 'b':\n" ); scanf( "%d", &b ); printf( "Enter number for 'c':\n" ); scanf( "%d", &c ); printf( "Enter number for 'd':\n" ); scanf( "%d", &d ); printf( "Enter number for 'e':\n" ); scanf( "%d", &e ); if(a > b && a > c && a > d && a > e); printf( "Letter 'a' is the largest number\n", a); if(a < b && a < c && a < d && a < e); printf( "Letter 'a' is the smallest number\n", a); if(b > a && b > c && b > d && b > e); printf( "Letter 'b' is the largest number\n", b); if(b < a && b < c && b < d && b < e); printf( "Letter 'b' is the smallest number\n", b); if(c > a && c > b && c > d && c > e); printf( "Letter 'c' is the largest number\n", c); if(c < a && c < b && c < d && c < e); printf( "Letter 'c' is the smallest number\n", c); if(d > a && d > b && d > c && d > e); printf( "Letter 'd' is the largest number\n", d); if(d < a && d < b && d < c && d < e); printf( "Letter 'd' is the smallest number\n", d); if(e > a && e > b && e > c && e > d); printf( "Letter 'e' is the largest number\n", e); if(e < a && e < b && e < c && e < d); printf( "Letter 'e' is the smallest number\n", e); return 0; }```
This just prints all the printf's. How do I get this to determine which number is largest and which is smallest?
• 10-09-2005
Rashakil Fol
You have semicolons after your if statements. Don't.
• 10-09-2005
quzah
You may want to study up on loops and arrays.

Quzah.
• 10-09-2005
cwr
Also, have a read of this FAQ and this FAQ for insight as to why using scanf in the manner you do above is not very wise.

Additionally, read up on the usage of printf. You are passing a variable, but no format specifier.
• 10-09-2005
lemnisca
The reason it is printing all the lines instead of just one is because you have a semicolon at the end of each if statement. This is the same as doing:
Code:

```if(expression)     ;```
which means: if the expression is true, do nothing.
So it will check each expression in your if statements, do nothing, then do the printf immediately afterwards.

Remove the extra semicolons and it will only do one of the printf statements.