1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include "stdafx.h"
float get_temp() {
float temp_grid[6][8] = {
{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }
};
float top = 0.0; float bot = 0.0; float left = 0.0; float right = 0.0;
int rows = 0;
int cols = 0;
printf("Enter a float temperature (example 5.36) for the top side of the metal plate: \n");
scanf("%.2f", &top);
for (cols = 0; cols < 8; cols++) {
temp_grid[0][cols] = top;
}
printf("Enter another float temperature for the bottom side of the metal plate: \n");
scanf("%.2f", &bot);
for (cols = 0; cols < 8; cols++) {
temp_grid[5][cols] = bot;
}
printf("Enter another float temperature for the left side of the metal plate: \n");
scanf("%.2f", &left);
for (rows = 1; rows < 5; rows++) {
temp_grid[rows][0] = left;
}
printf("Enter another float temperature for the right side of the metal plate: \n");
scanf("%.2f", &right);
for (rows = 1; rows < 5; rows++) {
temp_grid[rows][7] = right;
}
for (rows = 1; rows < 5; rows++) {
for (cols = 1; cols < 7; cols++) {
temp_grid[rows][cols] = (temp_grid[rows][cols - 1] + temp_grid[rows - 1][cols] + temp_grid[rows][cols + 1] + temp_grid[rows + 1][cols]) / 4; /*Left + right + top + bot / 4*/
printf("%.2f ", temp_grid[rows][cols]);
}
return 0.0;
}
}
int main()
{
get_temp();
return 0;
}
|