Guest User

Untitled

a guest
May 24th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. /*programma pou ypologizei statistika dedomenhs mias seiras timwn hliofaneias */
  2. #include <stdio.h>
  3. main ()
  4. {
  5. printf("Give values of sunshine duration for the seven days of a week, starting from \n");
  6. printf("the value for Monday. Each value should be an integer in the range (0..16].\n");
  7. int day,sunshine,min,max,sum,counter,minday,maxday,countermind;
  8. day=1;
  9. sunshine=17;
  10. min=17;
  11. max=0;
  12. sum=0;
  13. counter=1;
  14. minday=0;
  15. maxday=0;
  16. countermind=0;
  17. float avg;
  18. avg=0;
  19. while ( counter<=7)
  20. {
  21. printf("Day_%d:",day);
  22. scanf("%d",&sunshine);
  23. if (sunshine>16 || sunshine<0)
  24. {
  25. printf("value out of range\n");
  26. }
  27. else if (sunshine <=16 && sunshine >=0)
  28.  
  29. {
  30. counter++;
  31.  
  32. sum+=sunshine;
  33.  
  34. if (min>=sunshine)
  35. {
  36. if (min>sunshine)
  37. {
  38. countermind=1;
  39. }
  40. else
  41. {
  42. countermind++;
  43. }
  44. min=sunshine;
  45. minday=day;
  46.  
  47. }
  48.  
  49. if (max<=sunshine)
  50. {
  51. max=sunshine;
  52. maxday=day;
  53. }
  54. day++;
  55. }
  56.  
  57. }
  58. avg=(float)sum/7;
  59. printf("Average duration of sunshine = %.2f\n",avg);
  60. printf("Day with the longest sunshine = %d\n",maxday);
  61. printf("Day with the shortest sunshine = %d\n",minday);
  62. printf("Number of days with the shortest sunshine = %d\n",countermind);
  63. return 0;
  64.  
  65. }
Add Comment
Please, Sign In to add comment