Concetti Chiave
- The program is designed to find the two largest numbers from a set of 10 inputs.
- It initializes variables to store the two largest numbers as 'Max' and 'max' during input collection.
- The logic includes swapping values to ensure 'Max' always holds the largest and 'max' the second largest number.
- A loop iterates through the remaining inputs, updating 'Max' and 'max' as larger numbers are encountered.
- At the end of the process, the program outputs the two largest numbers found.
/* * Trovate i due numeri maggiori tra 10 valori, usando un approccio * simile all'Esercizio 3.24. Nota: potrete prendere in input ogni * valore soltanto una volta. * * SVILUPPO (top-down per raffinamenti successivi) * * TOP) prendere in input 10 valori, determinare i due maggiori * * RA1) inizializzare counter a 1 * prendere in input il primo valore * memorizzarlo in Max, incrementare counter di 1 * prendere in input il secondo valore * memorizzarlo in max, incrementare counter di 1 * se Max minore di max: * memorizzare Max in tmp * copiare max in Max, tmp in max * finché counter maggiore o uguale a 10: * prendere in input un valore * se valore maggiore Max: * copiare in max Max e in Max il nuovo valore * altrimenti se valore maggiore di max: * copiare in max il valore * incrementare counter di 1 * stampare Max e max * terminare programma */ #includeint main(void) { int counter, Max, max, number; counter = 1; printf("Enter %dst number: ", counter); scanf("%d", &Max); counter = counter + 1; printf("Enter %dst number: ", counter); scanf("%d", &max); counter = counter + 1; /* scambia i valori (in Max il massimo dei due) */ if (Max Max){ max = Max; Max = number; } else if (number > max) max = number; counter = counter + 1; } printf("The maximum values are %d and %d
", Max, max); return (0); }