You are on page 1of 1

#include<stdio.

h>

int main()

int i, max_index;

float arr[5], max;

printf("Please enter five numbers:\n ");

for (i = 0; i < 5; ++i)

scanf("%f", &arr[i]);

max = arr[0];//start off assuming that the 1st element is the max

for (i = 0; i < 5; i++)//now compare it with the rest of the array, updataing the max all along

if (arr[i] > max) {

max = arr[i];

max_index = i;

printf("Largest element = %.2f at index %d", max, max_index);

return 0;

You might also like