Skip to content

Instantly share code, notes, and snippets.

@Steffo99
Last active January 1, 2016 16:09
Show Gist options
  • Save Steffo99/8169182 to your computer and use it in GitHub Desktop.
Save Steffo99/8169182 to your computer and use it in GitHub Desktop.
Il compito delle vacanze di informatica. Facile.
#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