In: Computer Science
Sum
Bibi have an X × X array. Each array contains an integer a, and Bibi is curious about how much is the sum of all integers in each column.
Format Input:
The input consists of an integer T. The next T line contains X integers followed by an X × X array. Each array contains integers a.
Format Output
The output contains ”Case #T:” followed by X integers separated by spaces that indicate the sum of all the numbers in the i-th column.
Constraints
• 1 ≤ T ≤ 100
• 1 ≤ X ≤ 100
• 1 ≤ a ≤ 107
Sample Input 1 (standard input)
2
3
1 2 3
4 5 6
7 8 9
5
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
Sample Output 1 (standard output):
Case #1: 12 15 18
Case #2: 55 60 65 70 75
note : use c language, integer must be the same as the constraint, font use void/result code it under int main (){
All the explanations is given in the comments of the code itself.
Code--
#include<iostream>
using namespace std;
int main()
{
int T,i;
//prompt the user to give input fot T
cin>>T;
//declare an arry to store the output
int output[T][100]={0};
int size[T];
i=0;
//get inputs for each test case
while(i<T)
{
int X;
//prompt the user to give input fot
X
cin>>X;
size[i]=X;
//declare and int array of X x
X
int input[X][X];
for(int a=0;a<X;a++)
{
for(int
b=0;b<X;b++)
{
cin>>input[a][b];
}
}
//calculate the sum of each column
and save it in output array
for(int a=0;a<X;a++)
{
for(int
b=0;b<X;b++)
{
output[i][a]+=input[b][a];
}
}
i++;
}
//display the output
printf("\n\nOUTPUT:\n");
for(i=0;i<T;i++)
{
printf("Case #%d: ",i+1);
for(int j=0;j<size[i];j++)
{
printf("%d
",output[i][j]);
}
printf("\n");
}
}
Code Screenshot--
Output Screenshot--
Note--
The output is presented in exact same way as you have requested for.
Please upvote if you like the effort.