Thursday, April 3, 2014

PROGRAM TO PRINT THE UPPER TRIANGLE IN A MATRIX

//PROGRAM TO PRINT THE UPPER TRIANGLE IN A MATRIX

#include<conio.h>
#include<stdio.h>
#define row 3
#define col 3
void main()
{
int ar[row][col],i,j,n;
clrscr();

printf("enetr the elements of array\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&ar[i][j]);
}
}
printf(" the elements of array\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",ar[i][j]);
}
printf("\n\n");
}
if(row==col)
{
printf("the upper triangular matrix\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(j>i||j==i)
{
printf(" %d ",ar[i][j]);
}
else
{
printf("   ");
}
}
printf("\n\n");
}
}
else
printf("cant calculate th e upper matrix");
getch();
}

No comments:

Post a Comment