Thursday, September 13, 2012
Programm Find second maximum of an array
Find first and second maximum
#include <stdio.h>
void max(int v[], int n, int *max1, int *max2)
{
int i;
if(v[1]>v[0])
{
*max1=v[1];
*max2=v[0];
}
else
{
*max1=v[0];
*max2=v[1];
}
for(i=0;i<n;i++)
{
if(v[i]>*max1)
{
*max2=*max1;
*max1=v[i] ;
}
else if(v[i]>*max2)
*max2=v[i];
}
}
int main()
{
int max1, max2;
int v[100]={5, 6, 8 , 9, 25};
max(v,5, &max1, &max2);
printf("%d %d", max1, max2);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment