Monday, 19 November 2012

WAP to print the the second highest element in an array(using function).

  •  WAP to print the the second highest element in an array.(using function)
#include <stdio.h>
int second(int a[])
{
    int i,j,n;
    for(i=0;i<10;i++)
        for(j=i+1;j<10;j++)
            if(a[i]<a[j])
            a[i]=(a[i]+a[j])-(a[j]=a[i]);
    for(i=0;i<10;i++)
    {
        n=a[i+1];
        if(a[i]!=n)
        return n;
    }
    }
    void main()
    {
    int a[10],num,i;
    printf("Enter a array element");
    for(i=0;i<10;i++)
    scanf("%d",&a[i]);
    num=second(a);
    printf("%d is the second highest element",num);
    }

No comments:

Post a Comment