# Thread: program to find largest number from given numbers

1. ## program to find largest number from given numbers

I wrote c program to find smallest number from given numbers

Code:
```#include<stdio.h>
int main (void)
{
int numbers = { 9, 4, 2, 6 , 8, 3, 1} ;

int i = 0;

int smallest ;

smallest = numbers;

for (i = 0; i < 8; i++  )
{

if (smallest > numbers[i])
{

smallest = numbers[i];
}

}

printf ("smallest number = %d", smallest);

return 0;
}```
smallest number = 0

Why program doesn't show smallest number ? 2. That's because the smallest number is indeed 0. Notice that you declared the array as having 8 int values, then initialised it with 7 int literals. Therefore, the remaining element in the array is 0, and since you looped over the entire array, you found that 0 is the smallest number. 3. Originally Posted by laserlight That's because the smallest number is indeed 0. Notice that you declared the array as having 8 int values, then initialised it with 7 int literals. Therefore, the remaining element in the array is 0, and since you looped over the entire array, you found that 0 is the smallest number.
Thanks laserlight, I have another error in following code

code to find reverse number
Code:
```#include<stdio.h>
int main (void)
{
int numbers = { 9, 4, 2, 6 , 8, 3, 1} ;

int i = 0;

for (i = 7; i > 0; i--  )
{
printf ("%d", numbers[i]);

}

return 0;
}

output is 7138624  that is not the reverse number``` 4. What do you think is the problem and what have you tried for debugging, e.g., have you stepped through the loop with a debugger? Popular pages Recent additions find, int, largest, numbers, program 