AedenCak3

C Program to find the largest/max value in an array

Dec 6th, 2021
641
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int i,num;
  7.     printf("Enter the size of the array  :");
  8.     scanf("%d", &num);
  9.  
  10.     float arr[num], max;
  11.  
  12.     printf("enter elements in the array : ");
  13.  
  14.     for(i=0; i<num ; i++)
  15.     {
  16.         scanf("%f", &arr[i]);
  17.     }
  18.  
  19.     max= arr[0];
  20.  
  21.     for(i=1; i < num ; i++)
  22.     {
  23.         if(max<arr[i])
  24.         {
  25.             max=arr[i];
  26.         }
  27.  
  28.     }
  29.     printf("maximum value : %.2f", max);
  30. }
  31.  
RAW Paste Data