Extra 5% OFF Use Code: OL05
Free Shipping over ₹999

Find the largest element in an array

#include <stdio.h>
int main() {
  int num;
  double arr[100];
  printf("Enter the number of elements (1 to 100): ");
  scanf("%d", &num);

  for (int i = 0; i < num; ++i) {
    printf("Enter number%d: ", i + 1);
    scanf("%lf", &arr[i]);
  }

  // storing the largest number to arr[0]
  for (int i = 1; i < num; ++i) {
    if (arr[0] < arr[i]) {
      arr[0] = arr[i];
    }
  }

  printf("Largest element = %.2lf", arr[0]);

  return 0;
}

    Leave a Reply

    Your email address will not be published.

    Need Help?