Advertisement
Guest User

esercizio2.c

a guest
Oct 15th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. /*
  2. Esercizio 2
  3. Scrivere un programma che, dati 3 interi x, y e z, stampi:
  4. β€’il valore massimo
  5. β€’il valore minimo
  6. β€’la media
  7. Suggerimento: per il calcolo della media non Γ¨ possibile
  8. utilizzare solo il tipo di dato int...
  9. */
  10.  
  11. #include <stdio.h>
  12.  
  13. int max(int x, int y, int z){
  14. if((x>y) && (x>z)){
  15. return x;
  16. }else if(y>z){
  17. return y;
  18. }else{
  19. return z;
  20. }
  21. }
  22.  
  23. int min(int x, int y, int z){
  24. if((x<y) && (x<z)){
  25. return x;
  26. }else if(y<z){
  27. return y;
  28. }else{
  29. return z;
  30. }
  31. }
  32.  
  33. float media(int x, int y, int z){
  34. return ( ( x + y + z) / 3.0 ) ;
  35. }
  36.  
  37. int main(){
  38. int x, y, z;
  39.  
  40. printf("Inserisci il valore x:");
  41. scanf("%d", &x);
  42. while(getchar()!='\n');
  43.  
  44. printf("Inserisci il valore y:");
  45. scanf("%d", &y);
  46. while(getchar()!='\n');
  47.  
  48. printf("Inserisci il valore z:");
  49. scanf("%d", &z);
  50. while(getchar()!='\n');
  51.  
  52. printf("MAX(%d, %d, %d) = %d\n"
  53. "MIN(%d, %d, %d) = %d\n"
  54. "MEDIA(%d, %d, %d) = %.2f\n",
  55. x, y, z, max(x, y, z),
  56. x, y, z, min(x, y, z),
  57. x, y, z, media(x, y, z));
  58.  
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement