Advertisement
u53r

Trovare maggiore e minore tra N numeri

Mar 16th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. // Dati N numeri, trovare maggiore e minore
  2.  
  3. #include <stdio.h>
  4.  
  5. int main(int argc, char const *argv[])
  6. {
  7.     int N,i,x,mg,mn;
  8.     printf("Quanti numeri vuoi inserire?\n");
  9.     scanf("%d", &N);
  10.     printf("Inserisci i tuoi numeri\n");
  11.     scanf("%d", &x);
  12.     mg = mn = x;
  13.     for (i = 1; i < N; ++i){
  14.             scanf("%d", &x);
  15.             if(x < mn){
  16.                 mn = x;
  17.             }else if (x > mg){
  18.                 mg = x;
  19.             }
  20.         }
  21.  
  22.     printf("Maggiore: %d\nMinore: %d\n", mg,mn);
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement