training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

largest2.c (536B)


      1 /* Esercizio 3.27 
      2  *
      3  * Trova i 2 numeri maggiori tra 10 numeri
      4 */
      5 
      6 #include <stdio.h>
      7 
      8 int main()
      9 {
     10    int largest = 0, largest2 = 0, counter = 1, number;
     11 
     12    while(counter <= 10) {
     13       printf("Dammi un numero [%d di 10]: ", counter);
     14       scanf("%d", &number);
     15 
     16       if (number > largest2) {
     17 	 if (number > largest) {
     18 	    largest2 = largest;
     19 	    largest = number;
     20 	 }
     21 	 else largest2 = number;
     22       }
     23 
     24       ++counter;
     25    }
     26 
     27    printf("I 2 presunti largest sono %d e %d\n", largest2, largest);
     28 
     29    return 0;
     30 } /* E0F main */
     31