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

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 3 comments

kapil 6 years ago

wrong program


Crazy Hacker 6 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)


ashu 2 years ago

i want tree max in an array

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working