Question

In: Computer Science

Sum Bibi have an X × X array. Each array contains an integer a, and Bibi...

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 (){

Solutions

Expert Solution

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.


Related Solutions

Consider the problem of finding if an array contains a pair of integers with a sum...
Consider the problem of finding if an array contains a pair of integers with a sum of 100. The array contains n integers. a. Define the signature (header) of a C++ function that solves this problem (hint: inputs/outputs of function) b. Write the pseudocode or C++ body of the function (extra credit: write the most efficient algorithm) c. What is the asymptotic complexity of your algorithm? d. What would be the complexity of the best algorithm for this problem if...
I have a python program that must check if an integer is the sum of the...
I have a python program that must check if an integer is the sum of the squares of four consecutive prime numbers. However, when I run the program, it goes into an infinite while loop, and it doesn't give me any answer. I can only use the while, if, else, True and False commands. The code I'm using is n1=2   n2=3   n3=5   n4=7   n = int(input("n: "))   if (n==(n1**2)+(n2**2)+(n3**2)+(n4**2)):     print(n1,n2,n3,n4)   else :     i = 2     pr = True     next =...
Given a positive integer k and an array A[1..n] that contains the quiz scores of n...
Given a positive integer k and an array A[1..n] that contains the quiz scores of n students in ascending order, design a divide and conquer algorithm to efficiently count the number of students that have quiz scores in (100(i − 1)/k, 100i/k] for integers 1 ≤ i ≤ k. Let group i be the set of students with quiz scores in (100(i − 1)/k, 100i/k] for integers 1 ≤ i ≤ k. The counting result should be stored in G[1..k],...
C PROGRAMMING LANGUAGE Problem title : Bibi's Array Bibi also has an array containing N elements....
C PROGRAMMING LANGUAGE Problem title : Bibi's Array Bibi also has an array containing N elements. Like Lili, Bibi wants to know the highest frequency (most occurrences) and all elements which have that frequency. Format Input The first line contains an integer T stating the number of test cases. For each test case, the first line contains a single integer N which indicate the number of element in the array. The next line contains N integers Xi (1≤ i ≤...
Write a loop that sets each array element to the sum of itself and the next...
Write a loop that sets each array element to the sum of itself and the next element, except for the last element which stays the same. Be careful not to index beyond the last element. Ex: Initial scores: 10, 20, 30, 40 Scores after the loop: 30, 50, 70, 40 The first element is 30 or 10 + 20, the second element is 50 or 20 + 30, and the third element is 70 or 30 + 40. The last...
Write a loop that sets each array element to the sum of itself and the next...
Write a loop that sets each array element to the sum of itself and the next element, except for the last element which stays the same. Be careful not to index beyond the last element. Ex: Initial scores: 10, 20, 30, 40 Scores after the loop: 30, 50, 70, 40 The first element is 30 or 10 + 20, the second element is 50 or 20 + 30, and the third element is 70 or 30 + 40. The last...
Given an integer array sorted in non-decreasing order, there is exactly one integer in the array...
Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time. Return that integer. Input: arr = [1,2,2,6,6,6,6,7,10] Output:
Write a c program arrays2.c that checks if an integer array contains three identical consecutive elements....
Write a c program arrays2.c that checks if an integer array contains three identical consecutive elements. Assume the number of identical consecutive elements are no more than three if they exist. Sample input/output #1: Enter the length of the array: 11 Enter the elements of the array: -12 0 4 2 2 2 36 7 7 7 43 Output: The array contains 2 of three identical consecutive elements: 2 7 Sample input/output #2: Enter the length of the array: 4...
// Java // This method takes an integer array as well as an integer (the starting...
// Java // This method takes an integer array as well as an integer (the starting // index) and returns the sum of the squares of the elements in the array. // This method uses recursion. public int sumSquaresRec(int[] A, int pos) { // TODO: implement this method        return -1; // replace this statement with your own return }    // This method takes a character stack and converts all lower case letters // to upper case ones....
Create a method that takes a HashMap<Integer, Integer> and returns the sum of the keys of...
Create a method that takes a HashMap<Integer, Integer> and returns the sum of the keys of the HashMap.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT