Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Esercizio 2
- Scrivere un programma che, dati 3 interi x, y e z, stampi:
- β’il valore massimo
- β’il valore minimo
- β’la media
- Suggerimento: per il calcolo della media non Γ¨ possibile
- utilizzare solo il tipo di dato int...
- */
- #include <stdio.h>
- int max(int x, int y, int z){
- if((x>y) && (x>z)){
- return x;
- }else if(y>z){
- return y;
- }else{
- return z;
- }
- }
- int min(int x, int y, int z){
- if((x<y) && (x<z)){
- return x;
- }else if(y<z){
- return y;
- }else{
- return z;
- }
- }
- float media(int x, int y, int z){
- return ( ( x + y + z) / 3.0 ) ;
- }
- int main(){
- int x, y, z;
- printf("Inserisci il valore x:");
- scanf("%d", &x);
- while(getchar()!='\n');
- printf("Inserisci il valore y:");
- scanf("%d", &y);
- while(getchar()!='\n');
- printf("Inserisci il valore z:");
- scanf("%d", &z);
- while(getchar()!='\n');
- printf("MAX(%d, %d, %d) = %d\n"
- "MIN(%d, %d, %d) = %d\n"
- "MEDIA(%d, %d, %d) = %.2f\n",
- x, y, z, max(x, y, z),
- x, y, z, min(x, y, z),
- x, y, z, media(x, y, z));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement