C Online Compiler
Example: Find Largest Element in Array (Iterative) in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Find Largest Element in Array (Iterative) #include <stdio.h> int main() { // Step 1: Declare and initialize an integer array int numbers[] = {12, 45, 7, 89, 23, 67, 34}; int n = sizeof(numbers) / sizeof(numbers[0]); // Calculate array size // Step 2: Initialize 'max' with the first element of the array int max = numbers[0]; // Step 3: Iterate through the rest of the array (starting from the second element) for (int i = 1; i < n; i++) { // Step 4: If the current element is greater than 'max', update 'max' if (numbers[i] > max) { max = numbers[i]; } } // Step 5: Print the largest element found printf("The largest element in the array is: %d\n", max); return 0; }
Output
Clear
ADVERTISEMENTS