Concetti Chiave
- The program takes three different integers as input and calculates their sum, average, and product.
- It uses only single-selection if statements to determine the smallest and largest integers among the inputs.
- Incorrect code logic is present in the conditions for finding the smallest and largest integers.
- The program outputs the results in a structured dialogue format, displaying each calculation step-by-step.
- The code includes syntax errors, such as incorrect use of assignment operator instead of comparison in the if statements.
/* * Scrivete un programma C che prenda in input dalla tastiera tre * diversi interi e quindi visualizzi la somma, la media, il prodotto * il minore e il maggiore di questi numeri. * Usate soltanto soltanto la forma a selezione singola della * istruzione if che avete appreso in questo capitolo. * Lo schermo di dialogo deve apparire come il seguente: * * Input three different integers: 13 27 14 * Sum is 54 * Average is 18 * Product is 4914 * Smallest is 13 * Largest is 27 */ #includeint main(void) { int integer1, integer2, integer3, sum, average, product, smallest, largest; printf("Input three different integers: "); scanf("%d%d%d", &integer1, &integer2, &integer3); sum = integer1 + integer2 + integer3; printf("Sum is %d
", sum); average = sum / 3; printf("Average is %d
", average); product = integer1 * integer2 * integer3; printf("Product is %d
", product); /* Usando istruzioni if a selezione singola */ /* Ricerca del minimo */ if (integer1 = integer2) smallest = integer2; if (smallest >= integer3) smallest = integer3; /* Ricerca del massimo */ if (integer1 >= integer2) largest = integer1; if (integer1 ", smallest); printf("Larger is %d
", largest); return 0; }