Second Height Value from a Given Array
#include<stdio.h>
int main()
{
int i,n;
int a[100];
printf("Enter the size of array: \n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the %d value of array: \n",i+1);
scanf("%d",&a[i]);
}
int max=a[0];
int j=0;
for(i=0;i<n;i++)
{
while(a[i]>max)
{
max=a[i];
j=i;
}
}
int semax=a[n-j-1];
for(i=0;i<n;i++)
{
while(semax<a[i]&&j!=i)
semax=a[i];
}
printf("Max value of array is:%d\n",max);
printf("2nd Max value of array is:%d\n",semax);
}
#include<stdio.h>
int main()
{
int i,n;
int a[100];
printf("Enter the size of array: \n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the %d value of array: \n",i+1);
scanf("%d",&a[i]);
}
int max=a[0];
int j=0;
for(i=0;i<n;i++)
{
while(a[i]>max)
{
max=a[i];
j=i;
}
}
int semax=a[n-j-1];
for(i=0;i<n;i++)
{
while(semax<a[i]&&j!=i)
semax=a[i];
}
printf("Max value of array is:%d\n",max);
printf("2nd Max value of array is:%d\n",semax);
}
No comments:
Post a Comment