Write a C program Assume we have the following three arrays: int square[ 5 ][ 5
ID: 3762660 • Letter: W
Question
Write a C program
Assume we have the following three arrays: int square[ 5 ][ 5 ] = { 0 }, int product[ 5 ][ 6 ]; int table[ 5 ] [ 6 ] = { { 1, 2, 3, 4, 5}, {2, 4, 6, 8, 10}, {20,10, 5, 3, 1}, {3, 6, 9, 12, 15}}; Write a function to fill array "square" as shown below: (find the pattern and use iterations, please don't fill the array directly like a[2][2] = 9) write a function to fill array "square" as shown below: (find the pattern and use iterations, please don't fill the array directly like a[2][2] = 13) The partially initialized array "table" can be viewed as a primitive spreadsheet, in which the last column and bottom row have been left blank. Write the code to fill in this row and column with the totals of each column, each row, and the grand total Write the code to calculate the product of "square" times "table" and put the result in "product".Explanation / Answer
#include <stdio.h>
int square[5][5]={0};
int product[5][6];
int table[5][6]={
{1,2,3,4,5},
{2,4,6,8,10},
{20,10,5,3,1},
{3,6,9,12,15}
};
int function1()
{
int i,j,n=5;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
{
square[i][j]=(i+1)*(j+1);
}
}
}
}
int function2()
{
int i,j,n=5;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
square[i][j]=5*i+j+1;
}
}
}
int function3()
{
int i,j,n=5;
int sum=0;
for(i=0;i<n;i++)
{
sum=0;
for(j=0;j<n;j++)
{
sum+=table[i][j];
}
table[i][5]=sum;
}
for(i=0;i<n;i++)
{
sum=0;
for(j=0;j<n;j++)
{
sum+=table[j][i];
}
table[5][j]=sum;
}
}
int function4()
{
int i,j,k,sum=0,n=5;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
sum=0;
for(k=0;k<n;k++)
{
sum+=square[i][k]*table[k][j];
}
product[i][j]=sum;
}
}
}
int main(void) {
// your code goes here
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.