Question

In: Computer Science

Write a C++ program that reads in a table of numbers and finds out the average...

Write a C++ program that reads in a table of numbers and finds out the average of each row and column. This program should first take two numbers as number of rows and columns as input from the user

Solutions

Expert Solution

// Here is your required code

#include <iostream>
#include<stdlib.h>
using namespace std;

int main()
{
    int row,column,i,j,sum1=0,sum2=0;
    int average1,average2;
    cout<<"Enter the row and column"<<endl;
    cin>>row>>column;
    int arr[row][column];

    for(i=0;i<row;i++)
        for(j=0;j<column;j++)
        cin>>arr[i][j];
    system("cls");

    for(i=0;i<row;i++)
    {
        for(j=0;j<column;j++)
        cout<<arr[i][j]<<" ";
        cout<<endl;
    }

   for(int i=0;i<row;i++)
    {
        for(int j=0;j<column;j++)
        {
            sum1=sum1+arr[i][j];
        }
        average1=sum1/column;
        cout<<"The Average of "<<i+1<<" row "<<average1<<endl;
        sum1=0;
    }
    for(i=0;i<column;i++)
    {
        for(j=0;j<row;j++)
        {
            sum2=sum2+arr[j][i];
        }
        average2=sum2/row;
        cout<<"The Average of "<<i+1<<" column "<<average2<<endl;
        sum2=0;
    }
    return 0;
}

Output:

Note: If you have any query do write it in comment section

Please hit the like button if you find this helpful for you THANK YOU AND HAPPY LEARNING:)


Related Solutions

The Sum and The Average In C++, Write a program that reads in 10 integer numbers....
The Sum and The Average In C++, Write a program that reads in 10 integer numbers. Your program should do the following things: Use a Do statement Determine the number positive or negative Count the numbers of positive numbers, and negative Outputs the sum of: all the numbers greater than zero all the numbers less than zero (which will be a negative number or zero) all the numbers Calculate the average of all the numbers. The user enters the ten...
Part 1: Write a program that finds the sum and average of a series of numbers...
Part 1: Write a program that finds the sum and average of a series of numbers entered by the user. The program will first ask the user how many numbers there are. It then prompts the user for each of the numbers in turn and prints out the sum, average, the list of number from the user. Note: the average should always be a float, even if the user inputs are all ints. Part 2: Same as part 1 except...
C++ Write a program that reads candidate names and numbers of votes in from a file....
C++ Write a program that reads candidate names and numbers of votes in from a file. You may assume that each candidate has a single word first name and a single word last name (although you do not have to make this assumption). Your program should read the candidates and the number of votes received into one or more dynamically allocated arrays. In order to allocate the arrays you will need to know the number of records in the file....
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it...
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it in horizontal order of the screen
(C++) Write a program that reads a list of integers from the keyboard and print out...
(C++) Write a program that reads a list of integers from the keyboard and print out the smallest number entered. For example, if user enters 0 3 -2 5 8 1, it should print out -2. The reading stops when 999 is entered.
Write a c program that reads a .img file by rows and columns and prints out...
Write a c program that reads a .img file by rows and columns and prints out the arrays. The .img file contains h(the height) and w(the width) of the text size. An example .img file would be: 2 4 DFJSK HJ5JF HFDY5
Write a C ++ program which opens a file and reads several numbers, utilizing the fscanf()...
Write a C ++ program which opens a file and reads several numbers, utilizing the fscanf() function. Can you add few comments with explanations what is going on?
Write a C++ program that reads numbers from the user until the user enters a Sentinel....
Write a C++ program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input. Do the following: Output the sum of all even numbers Output the sum of all odd numbers Output the count of all even numbers Output the count of all odd numbers You must use loops and numbers to do this. You must not use any arrays or vectors for this program.
Write a C++ program that reads numbers from the user until the user enters a Sentinel....
Write a C++ program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input (other than the sentinel). Do the following: 1. Output the sum of all even numbers 2. Output the sum of all odd numbers 3. Output the count of all even numbers 4. Output the count of all odd numbers You must use alternation ('if' statements), loops and simple calculations to do...
Write a C++ program to read N numbers. Find sum, product, and average of N numbers
Write a C++ program to read N numbers. Find sum, product, and average of N numbers
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT