Last active
January 1, 2016 16:09
-
-
Save Steffo99/8169182 to your computer and use it in GitHub Desktop.
Il compito delle vacanze di informatica.
Facile.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <math.h> | |
#include <stdlib.h> | |
using namespace std; | |
int main() { | |
cout << "Questo programma calcola l'errore assoluto e la media di tre dati." << endl; | |
cout << "Inserisci i dati separati da invio." << endl; | |
float A, B, C, M, N, O, X; | |
cout << "Dato 1: "; | |
cin >> A; | |
cout << "Dato 2: "; | |
cin >> B; | |
cout << "Dato 3: "; | |
cin >> C; | |
//Se un numero è uguale, ferma il programma. | |
if (A == B || B == C || A == C) | |
{ | |
cerr << "Due numeri sono uguali tra loro." << endl; | |
cerr << "Impossibile continuare." << endl; | |
} | |
//Trova il numero massimo. | |
if (A > B && A > C) | |
{ | |
M = A; | |
} | |
if (B > A && B > C) | |
{ | |
M = B; | |
} | |
if (C > A && C > B) | |
{ | |
M = C; | |
} | |
cout << "Il numero massimo è " << M << endl; | |
//Trova il numero minimo. | |
if (A < B && A < C) | |
{ | |
N = A; | |
} | |
if (B < A && B < C) | |
{ | |
N = B; | |
} | |
if (C < A && C < B) | |
{ | |
N = C; | |
} | |
cout << "Il numero minimo è " << N << endl; | |
//Calcola l'errore assoluto. | |
X = (M + N) / 2; | |
cout << "Errore assoluto: (" << M << " + " << N << ") / 2 = " << X << endl; | |
//Calcola la media. | |
O = (A + B + C) / 3; | |
cout << "Media: (" << A << " + " << B << " + " << C << ") / 3 = " << O << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment