program to print upper & lower triangle of a matrix

Answer Posted / arka bandyopadhyay

#include<stdio.h>
#include<conio.h>
void main()
{
int arr[5][5],i,j;
clrscr();
printf("\n");
//upper triangle matrix
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
arr[i][j]=(i+j);
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(j<4-i)
{printf(" ");
}
else printf("%d",arr[i][j]);
}
printf("\n");
}
printf("\n");
//lower triangle matrix
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(j>=4-i)
{printf(" ");
}
else printf("%d",arr[i][j]);
}
printf("\n");
}

getch();
}

Is This Answer Correct ?    6 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a nested loop?

641


What is calloc() function?

614


What is difference between union All statement and Union?

622


What is the difference between a free-standing and a hosted environment?

634


Write a program to swap two numbers without using the third variable?

587






What is line in c preprocessor?

606


What are the different types of objects used in c?

566


Why do we need arrays in c?

571


What is s in c?

600


design and implement a data structure and performs the following operation with the help of file (included 1000 student marks in 5 sub. and %also) 1.how many students are fail in all 5 subjects (if >35) 2. delete all student data those are fail in all 5 subjects. 3. update the grace marks (5 no. if exam paper is 100 marks) 4. arrange the student data in ascending order basis of marks. 5.insert double of deleted students with marks in the list.

1485


a c code by using memory allocation for add ,multiply of sprase matrixes

2293


What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

617


Explain the concept and use of type void.

619


What is the size of a union variable?

594


what is the height of tree if leaf node is at level 3. please explain

1591