1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include<stdio.h> int find_largest(int [],int); int main() { int arr[30],size,largest,i; printf("Enter the size of the array maximum up to 30: "); scanf("%d",&size); printf("Enter the %d integer numbers: ",size); for(i=0;i<size;i++) scanf("%d",&arr[i]); largest = find_largest(arr,size); printf("\nThe largest element is: %d\n",largest); return 0; } int find_largest(int arr1[],int size1) { int temp_larg,i; temp_larg=arr1[0]; for(i=1;i<size1;i++) { if(arr1[i]>temp_larg) temp_larg=arr1[i]; } return(temp_larg); } |
Sample Input
Enter the size of the array maximum up to 30: 4
Enter the 4 integer numbers: 2 5 1 4
Sample Output
The largest element is: 5