Monday, July 13, 2015

Find the largest value from an array (take value by pointer)

#include <stdio.h>

int main()
{
    int i,n;

    int arr[100];

    printf("Enter number:");
    scanf("%d",&n);
    
    for(i=0;i<n;++i)  
    {
      
       scanf("%d",(arr+i));
    }
    for(i=1;i<n;++i)  
    {
       if(arr[0]<arr[i]) 
           arr[0]=arr[i];
    }
    printf("Largest number is= %d",arr[0]);
    return 0;
}


output:


Enter number:6
7 8 4 9 0 3
Largest number is = 9

No comments:

Post a Comment