Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*programma pou ypologizei statistika dedomenhs mias seiras timwn hliofaneias */
- #include <stdio.h>
- main ()
- {
- printf("Give values of sunshine duration for the seven days of a week, starting from \n");
- printf("the value for Monday. Each value should be an integer in the range (0..16].\n");
- int day,sunshine,min,max,sum,counter,minday,maxday,countermind;
- day=1;
- sunshine=17;
- min=17;
- max=0;
- sum=0;
- counter=1;
- minday=0;
- maxday=0;
- countermind=0;
- float avg;
- avg=0;
- while ( counter<=7)
- {
- printf("Day_%d:",day);
- scanf("%d",&sunshine);
- if (sunshine>16 || sunshine<0)
- {
- printf("value out of range\n");
- }
- else if (sunshine <=16 && sunshine >=0)
- {
- counter++;
- sum+=sunshine;
- if (min>=sunshine)
- {
- if (min>sunshine)
- {
- countermind=1;
- }
- else
- {
- countermind++;
- }
- min=sunshine;
- minday=day;
- }
- if (max<=sunshine)
- {
- max=sunshine;
- maxday=day;
- }
- day++;
- }
- }
- avg=(float)sum/7;
- printf("Average duration of sunshine = %.2f\n",avg);
- printf("Day with the longest sunshine = %d\n",maxday);
- printf("Day with the shortest sunshine = %d\n",minday);
- printf("Number of days with the shortest sunshine = %d\n",countermind);
- return 0;
- }
Add Comment
Please, Sign In to add comment