c - two-dimensional table (monthly scan of 3 regions)
I need to make a two-dimensional table that scans monthly rainfall of the western, eastern, and central regions.
The user must enter all 12 numbers for each region.
The input should look something like this:
Western:
1
1
1
1
1
1
(ending around the 12th #)
Eastern:
(same thing as the first)
Central
(same)
|
What I did and it's a wreck:
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
|
int main()
{
int western[12][12], eastern[12][12], central[12][12], x=1;
printf("Enter the rainfall in the western, eastern, and central regions. \n\n");
for(i=0; i<12 ;i++)
{
printf("# %d \n", x++);
printf("western: ");
//printf("eastern: \n");
for(j=0;j<12;j++)
{
scanf("%d", &western);
//scanf("%d", &eastern);
}
}
//printf("central: ");
// scanf("%d", ¢ral);
//printf("\n");
}
|
Last edited on
You have 3 regions and each region has 12 months -> 36 numbers.
Just one array is enough.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <stdio.h>
#define NUM_REGIONS 3
#define NUM_MONTHS 12
int main()
{
int data[NUM_REGIONS][NUM_MONTHS] = {0};
int region, month;
for (region = 0; region < NUM_REGIONS; region++)
{
for (month = 0; month < NUM_MONTHS; month++)
{
/*To do read data into data[region][month] */
}
}
}
|
Topic archived. No new replies allowed.