#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],n,i,max=0,smax=0,tmax=0; // declared the array a with size 20
clrscr();
printf("\n Enter the number of elements for 1-D array : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter element [%d] : ",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(max<a[i])
max=a[i];
}
printf("\n Greatest element from above array inserted is : %d",max);
for(i=0;i<n;i++)
{ if(smax<a[i]&&a[i]<max)
smax=a[i];
}
printf("\n2nd Greatest element from above array inserted is : %d",smax);
for(i=0;i<n;i++)
{ if(tmax<a[i]&&a[i]<smax &&a[i]<max)
tmax=a[i];
}
printf("\n3rd Greatest element from above array inserted is : %d",tmax);
getch();
}
#include<conio.h>
void main()
{
int a[20],n,i,max=0,smax=0,tmax=0; // declared the array a with size 20
clrscr();
printf("\n Enter the number of elements for 1-D array : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter element [%d] : ",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(max<a[i])
max=a[i];
}
printf("\n Greatest element from above array inserted is : %d",max);
for(i=0;i<n;i++)
{ if(smax<a[i]&&a[i]<max)
smax=a[i];
}
printf("\n2nd Greatest element from above array inserted is : %d",smax);
for(i=0;i<n;i++)
{ if(tmax<a[i]&&a[i]<smax &&a[i]<max)
tmax=a[i];
}
printf("\n3rd Greatest element from above array inserted is : %d",tmax);
getch();
}
No comments:
Post a Comment