C Examples Array Largest Element
# C Language Example - Find the Largest Element Value in an Array
[ C Language Examples](#)
Find the largest element value in an array.
## Example 1
#includeint main(){int array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; int loop, largest; largest = array; for(loop = 1; loop<10; loop++){if(largest<array)largest = array; }printf("The largest element is %d", largest); return 0; }
The output is:
The largest element is 9
User-defined output:
## Example 2
#includeint main(){int i, n; float arr; printf("Enter the number of elements (0~100οΌ: "); scanf("%d", &n); printf("n"); // Receive user input for(i = 0; i<n; ++i){printf("Enter a number %d: ", i+1); scanf("%f", &arr); }// Loop, and store the largest element in arrfor(i = 1; i<n; ++i){// If you want to find the minimum value, you can change the if(arr<arr)arr = arr; }printf("The largest element is = %.2f", arr); return 0; }
The output is:
Enter the number of elements (0~100οΌ: 4Enter a number 1: 12Enter a number 2: 23Enter a number 3: 1 Enter a number 4: 3The largest element is = 23.00
[ C Language Examples](#)
YouTip