Site icon T4Tutorials.com

Program to Print Upperhalf and Lowerhalf Triangle of Square Matrix in CPP (C plus plus)

Program to Print Upper half and Lower half Triangle of Square Matrix in CPP (C plus plus)

In this tutorial, we will learn about Program to Print Upper half and Lower half Triangle of Square Matrix in CPP (C plus plus).

#include<iostream>
 
using namespace std;
 
int main()
{
    int array[10][10];
	int k;
	int i;
	int j;

    
    cout<<"Please enter the size of the Matrix (MIN 3, MAX 5):";
    cin>>k;
    
    cout<<endl<<"Please enter the Matrix row wise:"<<endl;
    
    for(i=0;i<k;i++)
        for(j=0;j<k;++j)
            cin>>array[i][j];
    
    cout<<endl;
    
    for(i=0;i<k;++i)
    {
        for(j=0;j<k;++j)
        {
            if(i<j)
                cout<<array[i][j]<<" ";
                
            else
                cout<<"  ";
        }
        
        cout<<endl;
    }
    
    cout<<endl;
    
    for(i=0;i<k;++i)
    {
        for(j=0;j<k;++j)
        {
            if(j<i)
                cout<<array[i][j]<<" ";
            else
                cout<<" ";
        }
        cout<<endl;
    }
 
    return 0;
}

Output:

 

Program to Print Upperhalf and Lowerhalf Triangle of Square Matrix in CPP (C plus plus)
Program to Print Upper half and Lower half Triangle of Square Matrix in CPP (C plus plus)

YouTube video player

Exit mobile version