c Program to display largest element in the array
#include <stdio.h>int main()
{ int i,n; float arr[100]; printf("Enter total number of elements(1 to 100): "); scanf("%d",&n); printf("\n"); for(i=0;i<n;++i) /* Stores number entered by user. */ { printf("Enter Number %d: ",i+1); scanf("%f",&arr[i]); } for(i=1;i<n;++i) /* Loop to store largest number to arr[0] */ { if(arr[0]<arr[i]) /* Change < to > if you want to find smallest element*/ arr[0]=arr[i]; } printf("Largest element = %.2f",arr[0]); return 0; }
OUTPUT:- ---------------------------------
Enter total number of elements(1 to 100): 5 Enter Number 1: 22 Enter Number 2: 39 Enter Number 3: 83 Enter Number 4: 41 Enter Number 5: 68 Largest element = 83.00 --------------------------------