Search This Blog

Sunday 6 May 2018

Solution of Programming Lab Exercise 2 - Week 4


#include <iostream>
using namespace std;

int displayDiagonal(int, int);

main ( )
{   int row, col;
    cout << "Enter the Number of rows: " ;
cin >> row ;

cout << "Enter the Number of columns:" ;
cin >> col ;

if ( row==col )

displayDiagonal ( row, col );
}
else

cout << "Wrong input!! Number of rows should be equal to Number of columns " << endl;
}

}

int displayDiagonal(int row, int col)
{
int i, j;

for (i=1;i<=row;i++)
{
for (j=1;j<=col;j++)
{
if (i==j)
cout << i;
else
cout << 0;
}
cout <<endl;
}
return 1;
}

No comments:

Post a Comment