ghorardim

array - 1 max value

Oct 8th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #define sz 12
  3. int arr[sz];
  4. int main ()
  5. {
  6.     int i,n,mx,idx;
  7.     scanf("%d",&n);
  8.     for(i=0; i<n; i++)
  9.     {
  10.         scanf("%d",&arr[i]);
  11.     }
  12.     mx=arr[0];
  13.     idx=0;
  14.     for(i=1; i<n; i++)
  15.     {
  16.      
  17.         if(arr[i]>mx)
  18.         {
  19.  
  20.             mx=arr[i];
  21.             idx=i;
  22.          
  23.         }
  24.     }
  25.  
  26.     printf("max=%d index=%d\n",mx,idx);
  27.     return(0);
  28. }
  29. /*
  30. 5
  31. 4 6 23 65 45
  32. */
Advertisement
Add Comment
Please, Sign In to add comment