Search
 
SCRIPT & CODE EXAMPLE
 

CPP

sum of row s2 d array c++

#include <iostream>
using namespace std;
int main()
{
	int size=2;
    int a[size][size];
    int row, col, sum;
    cout<<"Please Enter elements in array of size "<<size<<"x"<<size<<endl<<endl;
    for(row=0; row<size; row++)
    {
        for(col=0; col<size; col++)
        {
            cin>>a[row][col];
        }
    }
     for(row=0; row<size; row++)
    {
        for(col=0; col<size; col++)
        {
            cout<<a[row][col]<<" ";
        }
        cout<<endl;
    }
    for(row=0; row<size; row++)
    {
        sum = 0;
        for(col=0; col<size; col++)
        {
            sum = sum + a[row][col];
        }
        cout<<"Sum of elements of Row: "<< row+1<<" is "<< sum<<endl;
    }    
    for(col=0; col<size; col++)
    {
        sum = 0;
        for(row=0; row<size; row++)
        {
            sum += a[row][col];
        }
        cout<<"Sum of elements of Column: " <<row+1<<" is "<<sum<<endl;
    }
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c pre-processor instructions 
Cpp :: c define 
Cpp :: iterate over map c++ 
Cpp :: c++ reverse string 
Cpp :: new line in c++ 
Cpp :: how to make Dijkstra in c++ 
Cpp :: Reverse words in a given string solution in c++ 
Cpp :: macros in c++ 
Cpp :: function overloading in c++ 
Cpp :: c++ string slicing 
Cpp :: c++ initialize static variable 
Cpp :: insert in vector 
Cpp :: c++ convert const char* to int 
Cpp :: how to concatenate two vectors in c++ 
Cpp :: c++ pointers and functions 
Cpp :: cpp template 
Cpp :: C++ Nested if...else 
Cpp :: is anagram c++ 
Cpp :: c++ for each loop 
Cpp :: find pair with given sum in the array 
Cpp :: initialise 2d vector in c++ 
Cpp :: pointers and arrays in c++ 
Cpp :: cpp ignore warning in line 
Cpp :: c++ polymorphism 
Cpp :: c++ while loop 
Cpp :: c++ compare type 
Cpp :: namespace file linking c++ 
Cpp :: how to find size of int in c++ 
Cpp :: c++ program to find gcd of 3 numbers 
Cpp :: minimum or maximum in array c++ 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =