RSS

PROGRAM TO FIND THE SUM OF LOWER DIAGONAL ELEMENTS (USING POINTERS)

21 Nov

// THIS PROGRAM FINDS THE SUM OF LOWER DIAGONAL ELEMENTS IN A MATRIX(USING POINTERS)

#include <iostream.h>
#include <conio.h>

void main()
{
clrscr();
int size;
cout<<“\nENTER THE SIZE OF THE MATRIX\n”;
cin>>size;
int **arr = new int *[size];

for(int i =0; i<size; i++)
arr[i] = new int[size];

cout<<“\nINPUT THE MATRIX \n”;

for(i =0; i<size; i++)
for(int j =0; j<size; j++)
cin>> *(*(arr+i) + j);

int sum = 0;

for(i =0; i<size; i++)
for(j = 0; j<size; j++)
if( i +j == size – 1)
sum += *(*(arr +i) + j);

cout<<“\nTHE SUM OF THE LOWER DIAGONAL ELEMENTS IS “<<sum;
getch();
}

Advertisements
 
Leave a comment

Posted by on November 21, 2015 in Matrices, Pointers and Arrays

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: