S
shauncarter1
I was recently given this assignment in my introduction to C
programming class. I have been working on this problem for hours and
I am at my wits end. The following code needs to be produced.
two-dimensional array of integers. The array should be declared as a
10-by-20 array of integers in main().
b. Modify this function so that it also displays the row and column
number of the element with the maximum value.<<<
So far I have developed the program up to this point:
#include <stdio.h>
int findMax(int[10][20]);
int main()
{
int val[10][20] =
{23, 54, 35, 11, 10, 94, 88, 56, 13, 14, 99, 63, 28, 94, 77, 45,
12, 19, 91, 76,
24, 55, 36, 16, 19, 95, 89, 57, 18, 34, 92, 64, 29, 91, 44, 32,
89, 11, 98, 88,
76, 18, 98, 10, 48, 19, 89, 13, 18, 14, 13, 84, 85, 19, 87, 92,
91, 18, 19, 67,
76, 18, 98, 10, 48, 19, 89, 13, 18, 14, 13, 84, 85, 19, 87, 92,
91, 18, 19, 67,
76, 18, 98, 10, 48, 19, 89, 13, 18, 14, 13, 84, 85, 19, 87, 92,
91, 18, 19, 67,
76, 18, 98, 10, 48, 19, 89, 13, 18, 14, 13, 84, 85, 19, 87, 92,
91, 18, 19, 67,
76, 18, 98, 10, 48, 19, 89, 13, 18, 14, 13, 84, 85, 19, 87, 92,
91, 18, 19, 67,
76, 18, 98, 10, 48, 19, 89, 13, 18, 14, 13, 84, 85, 19, 87, 92,
91, 18, 19, 67,
76, 18, 98, 10, 48, 19, 89, 13, 18, 14, 13, 84, 85, 19, 87, 92,
91, 18, 19, 67,
76, 18, 98, 10, 48, 19, 89, 13, 18, 14, 13, 84, 85, 19, 87, 92,
91, 18, 19, 67};
printf("The maximum value is %d", findMax(val));
return 0;
}
int findMax(int nums[10][20])
{
int q, pass, temp;
for (pass = 0; pass <= 6; pass++)
{
for (q = 0; q <= 6; q++)
{
if(nums[q][q] > nums[q +1][q + 1])
{
temp = nums[q][q];
nums[q][q] = nums[q+1][q+1];
nums[q + 1][q + 1] = temp;
}
}
}
return(temp);
}
I cannot figure out for the life of me what I am doing or not doing to
make this program work. So I am calling on the gurus for a little
advice.
Thanks,
Shaun
programming class. I have been working on this problem for hours and
I am at my wits end. The following code needs to be produced.
two-dimensional array of integers. The array should be declared as a
10-by-20 array of integers in main().
b. Modify this function so that it also displays the row and column
number of the element with the maximum value.<<<
So far I have developed the program up to this point:
#include <stdio.h>
int findMax(int[10][20]);
int main()
{
int val[10][20] =
{23, 54, 35, 11, 10, 94, 88, 56, 13, 14, 99, 63, 28, 94, 77, 45,
12, 19, 91, 76,
24, 55, 36, 16, 19, 95, 89, 57, 18, 34, 92, 64, 29, 91, 44, 32,
89, 11, 98, 88,
76, 18, 98, 10, 48, 19, 89, 13, 18, 14, 13, 84, 85, 19, 87, 92,
91, 18, 19, 67,
76, 18, 98, 10, 48, 19, 89, 13, 18, 14, 13, 84, 85, 19, 87, 92,
91, 18, 19, 67,
76, 18, 98, 10, 48, 19, 89, 13, 18, 14, 13, 84, 85, 19, 87, 92,
91, 18, 19, 67,
76, 18, 98, 10, 48, 19, 89, 13, 18, 14, 13, 84, 85, 19, 87, 92,
91, 18, 19, 67,
76, 18, 98, 10, 48, 19, 89, 13, 18, 14, 13, 84, 85, 19, 87, 92,
91, 18, 19, 67,
76, 18, 98, 10, 48, 19, 89, 13, 18, 14, 13, 84, 85, 19, 87, 92,
91, 18, 19, 67,
76, 18, 98, 10, 48, 19, 89, 13, 18, 14, 13, 84, 85, 19, 87, 92,
91, 18, 19, 67,
76, 18, 98, 10, 48, 19, 89, 13, 18, 14, 13, 84, 85, 19, 87, 92,
91, 18, 19, 67};
printf("The maximum value is %d", findMax(val));
return 0;
}
int findMax(int nums[10][20])
{
int q, pass, temp;
for (pass = 0; pass <= 6; pass++)
{
for (q = 0; q <= 6; q++)
{
if(nums[q][q] > nums[q +1][q + 1])
{
temp = nums[q][q];
nums[q][q] = nums[q+1][q+1];
nums[q + 1][q + 1] = temp;
}
}
}
return(temp);
}
I cannot figure out for the life of me what I am doing or not doing to
make this program work. So I am calling on the gurus for a little
advice.
Thanks,
Shaun