ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming

Write a program using arrays to find the largest and second largest numbers out of given 50 numbers.

Updated on March 13, 2010
Programming With C
Programming With C

Write a program using arrays to find the largest and second largest numbers out of given 50 numbers.

#include

#include

void main()

{

int a[50],i,max,smax;

clrscr();

printf("Enter the value of a:");

for(i=0;i<50;i++)

scanf("\n%d",&a[i]);

{max=a[i];

for(i=0;i=max)

max=a[i];}

printf("\n The largest value is:%d",max);

smax=a[i];

for(i=0;i=smax)

smax=a[i];

printf("\nThe second largest value is:%d",smax);

getch();

}

Output
Enter the values of a:548
1
45
65
256
8
5
31
54
25
36
81
67
13
266
16
92
35
75
154
85
64
38
91
60
69
15
16
46
53
27
559
56
78
77
37
49
83
19
20
54
214
22
48
90
64
37
54
26
596
The largest value is:596
The second largest value is:559

Comments

    0 of 8192 characters used
    Post Comment

    • profile image

      ashu 3 years ago

      i want tree max in an array

    • profile image

      Crazy Hacker 7 years ago

      Yeah its wrong program

      u can't define library functions and for loop is also wrong and program also taken many values not limited

      better luck next time

      Maheshkumar(ALIET)

    • profile image

      kapil 7 years ago

      wrong program