How to find second highest number in array by c programming

How to find second highest number in array by c programming

if you are using turbo c compiler please use #include<conio.h> header file. and if you are using devc++ or any other compiler than simply go through the given program below.



#include <stdio.h>
int main(){
    
    char a[20],i,n,temp;
    printf("enter size of array\n");
    scanf("%d",&n);
    printf("enter elements of array\n");
    for(i=0;i<n;i++){
       scanf("%d",&a[i]); 
        
    }
    
    for(i=0;i<n;i++){
        
        if(a[i]>a[0])
        {
           temp=a[0]; 
           a[0]=a[i];
           a[i]=temp;
           
           
            
        }
    }
    
    for(i=1;i<n;i++){
        
        if(a[i]>a[1]){
            a[1]=a[i];
        }
    }
    printf("second highest number is %d\n",a[1]);
    
}

How to find second highest number in array by c programming

Comments

Post a Comment

Popular posts from this blog

c program to convert any three digit number in words

c program to remove characters in string except alphabets