Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #define _USE_MATH_DEFINES
  3. #include <math.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6. #include <string.h>
  7. #define MAX_ROW 2
  8. #define MAX_COLUMNS 7
  9.  
  10. void read(double[][MAX_COLUMNS]);
  11. void calc(double[][MAX_COLUMNS], int *, int *);
  12. void print(double[][MAX_COLUMNS],char[][64], int, int);
  13.  
  14. int main(void)
  15. {
  16. int i;
  17. double weather[MAX_ROW][MAX_COLUMNS];
  18. char days[7][64];
  19. int min, max;
  20.  
  21. for (i = 0; i < 7; i++)
  22. {
  23. printf("name of day %d:\n", i);
  24. gets(days[i]);
  25. }
  26. read(weather);
  27.  
  28. calc(weather, &min, &max);
  29.  
  30. print(weather, days, min, max);
  31.  
  32. return 0;
  33. }
  34. void read(double a[][MAX_COLUMNS])
  35. {
  36. int i, j;
  37.  
  38. for (i = 0; i < MAX_ROW; i++)
  39. {
  40. for (j = 0; j < MAX_COLUMNS; j++)
  41. {
  42. if (i == 0)
  43. {
  44. printf("Give temp of day %d: \n", j+1);
  45. }
  46. else
  47. {
  48. printf("Give temp of night %d: \n", j+1);
  49.  
  50. }
  51. scanf("%lf%*c", &a[i][j]);
  52. }
  53. }
  54. }
  55. void calc(double a[][MAX_COLUMNS], int *min, int *max)
  56. {
  57. int i, j;
  58. double high, low;
  59. high = a[0][0];
  60. low = a[0][0];
  61.  
  62. for (i = 0; i < MAX_ROW; i++)
  63. {
  64. for (j = 0; j < MAX_COLUMNS; ++j)
  65. {
  66. if (high < a[i][j])
  67. {
  68. high = a[i][j];
  69. *max = j;
  70. }
  71. if (low > a[i][j])
  72. {
  73. low = a[i][j];
  74. *min = j;
  75. }
  76. }
  77. }
  78. }
  79. void print(double a[][MAX_COLUMNS],char dag[][64], int min, int max)
  80. {
  81. printf("Min:\tNight:\t%s = %.1lf", dag[min],a[1][min]);
  82. printf("\n\tDay:\t%s = %.1lf\n", dag[min], a[0][min]);
  83.  
  84. printf("Max:\tNight:\t%s = %.1lf", dag[max], a[1][max]);
  85. printf("\n\tDay:\t%s = %.1lf\n", dag[max], a[0][max]);
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement