Question

In: Computer Science

Pyramid of oranges, 2^x in each row, total for n rows using scheme language also include...

Pyramid of oranges, 2^x in each row, total for n rows using scheme language also include comments

Solutions

Expert Solution

// C++ program to find the sum
// of each row and column of a matrix

#include <iostream>
using namespace std;

// Get the size m and n
#define m 4
#define n 4

// Function to calculate sum of each row
void row_sum(int arr[m][n])
{

   int i,j,sum = 0;

   cout << "\nFinding Sum of each row:\n\n";

   // finding the row sum
   for (i = 0; i < 4; ++i) {
       for (j = 0; j < 4; ++j) {

           // Add the element
           sum = sum + arr[i][j];
       }

       // Print the row sum
       cout
           << "Sum of the row "
           << i << " = " << sum
           << endl;

       // Reset the sum
       sum = 0;
   }
}

// Function to calculate sum of each column
void column_sum(int arr[m][n])
{

   int i,j,sum = 0;

   cout << "\nFinding Sum of each column:\n\n";

   // finding the column sum
   for (i = 0; i < 4; ++i) {
       for (j = 0; j < 4; ++j) {

           // Add the element
           sum = sum + arr[j][i];
       }

       // Print the column sum
       cout
           << "Sum of the column "
           << i << " = " << sum
           << endl;

       // Reset the sum
       sum = 0;
   }
}

// Driver code
int main()
{

   int i,j;
   int arr[m][n];

   // Get the matrix elements
   int x = 1;
   for (i = 0; i < m; i++)
       for (j = 0; j < n; j++)
           arr[i][j] = x++;

   // Get each row sum
   row_sum(arr);

   // Get each column sum
   column_sum(arr);

   return 0;
}


Related Solutions

4 function calculator (op1 oper op2) using scheme language also include comments
4 function calculator (op1 oper op2) using scheme language also include comments
#include using namespace std; int menu(){    int x;    cout<<"1.Add Entry\n";    cout<<"2.Edit Entry\n";   ...
#include using namespace std; int menu(){    int x;    cout<<"1.Add Entry\n";    cout<<"2.Edit Entry\n";    cout<<"3.remove Entry\n";    cout<<"4.print Entry\n";    cout<<"5.Close Console\n";    cout<<"Enter Your Choice:-";    cin>>x;              return x; } int main() {    int x;    int entry[1000];    int entnum = 0;    int num = 0;    int nom =0;     while (1)     {         int choice = menu();         if (choice == 1){            cout<<"A entry " <<...
Create the appropriate 2 x 2 table for the data. Include appropriate row and column labels and complete the table with information provided in the scenario.
A. Researchers conducted a case control study to identify the association between alcohol consumption and esophageal cancer among men. They enrolled 187 men with esophageal cancer and 715 men without esophageal cancer. The men were asked about their regular alcohol consumption and the men were categorized as either drinking ≥80 g/day (exposed) or
Show that, for each natural number n, (x − 1)(x − 2)(x − 3). . .(x...
Show that, for each natural number n, (x − 1)(x − 2)(x − 3). . .(x − n) − 1 is irreducible over Q, the rationals.
2. Using matrices, create an algorithm that takes a matrix of dimension N x N and...
2. Using matrices, create an algorithm that takes a matrix of dimension N x N and feed it in a spiral shape with the sequential number from 1 to N^2. Then do an algorithm in PSEint
4. For a signal x(n)=sin(2*pi*n/3) defined for n=0to7, evaluate the Fast Fourier Transform using signal flow...
4. For a signal x(n)=sin(2*pi*n/3) defined for n=0to7, evaluate the Fast Fourier Transform using signal flow graph. (Use decimation in frequency Algorithm)     
For a signal x(n)=sin(2*pi*n/5) defined for n=0to7, evaluate the Fast Fourier Transform using signal flow graph....
For a signal x(n)=sin(2*pi*n/5) defined for n=0to7, evaluate the Fast Fourier Transform using signal flow graph. (Use decimation in Time Algorithm).                                               
For a signal x(n)=sin(2*pi*n/5) defined for n=0to7, evaluate the Fast Fourier Transform using signal flow graph....
For a signal x(n)=sin(2*pi*n/5) defined for n=0to7, evaluate the Fast Fourier Transform using signal flow graph. (Use decimation in Time Algorithm).                                               
Using the quotient rule find the derivative of the function in each case: I. f(x)=(x^2)/(x-5) ii....
Using the quotient rule find the derivative of the function in each case: I. f(x)=(x^2)/(x-5) ii. g(x)=(2x)/(x^2+2) iii. h(x)=(sin x)/x
Evaluate each integral using trig substitutions 1.) Integral of (3x^5dx)/(sqrt(16-x^2) 2.) Integral of (sqrt(x^2-16)dx)/x 3.) Integral...
Evaluate each integral using trig substitutions 1.) Integral of (3x^5dx)/(sqrt(16-x^2) 2.) Integral of (sqrt(x^2-16)dx)/x 3.) Integral of (6dx)/(16+16x^2)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT