# Thread: second biggest in an array

1. ## second biggest in an array

input array elements:5,6,3,1,7
output:biggest number:7, second biggest=7

can anyone help me out what is wrong???

Code:
```/*c program to find out the maximum and the second maximum number from an
array of integers*/
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[10];
int i;
int n;
int big;
int sec_big;
printf("\n How many:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter %d number:",i+1);
scanf("%d",arr[i]);
}
big=arr[0];
for(i=0;i<n;i++)
{
if(arr[i]>big)
{
big=arr[i];
}
}
sec_big=arr[0];
for(i=0;i<n;i++)
{
if((arr[i]>sec_big)&&(sec_big<big))
{
sec_big=arr[i];
}
}
printf("\n Biggest number=%d,second biggest=%d",big,sec_big);
getch();
}```

2. Originally Posted by Pulock2009
input array elements:5,6,3,1,7
output:biggest number:7, second biggest=7

can anyone help me out what is wrong???

Code:
```/*c program to find out the maximum and the second maximum number from an
array of integers*/
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[10];
int i;
int n;
int big;
int sec_big;
printf("\n How many:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter %d number:",i+1);
scanf("%d",arr[i]);
}
big=arr[0];
for(i=0;i<n;i++)
{
if(arr[i]>big)
{
big=arr[i];
}
}
sec_big=arr[0];
for(i=0;i<n;i++)
{
if((arr[i]>sec_big)&&(sec_big<big))
{
sec_big=arr[i];
}
}
printf("\n Biggest number=%d,second biggest=%d",big,sec_big);
getch();
}```
You left off the '&" in scanf S/B
Code:
`scanf("%d",&arr[i]);`
Edit:
Having fixed that, your code still has problems. Try to think it through. :-)

4. Originally Posted by Pulock2009
You need to work with two variables...

Code:
```Int Biggest = 0;
Int Second = 0;

for (x = 0; x < Elements; x++)
{ if (Array[x] > Biggest)
{ Second = Biggest;
Biggest = Array[x]; } }```

5. Originally Posted by Pulock2009
I don't think it's good practice to use void main().

Code:
```/*c program to find out the maximum and the second maximum number from an
array of integers*/
#include<stdio.h>

int main(void)
{
int arr[10];
int i;
int n;
int big;
int sec_big;
printf("\n How many:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter %d number:",i+1);
scanf("%d",&arr[i]);
}
big=arr[0];
sec_big = 0;
for(i=0;i<n;i++)
{
if(arr[i]>big)
{
sec_big = big;
big=arr[i];
}
}
printf("\n Biggest number= %d ,second biggest= %d\n",big,sec_big);
return 0;
}```

6. try

if
((arr[i]>sec_big)&&(arr[i]<big))

7. many many thanks to all of you!!!