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

Can we access the array using a pointer in c language?

569


List some of the static data structures in C?

768


What is floating point constants?

701


What are the differences between new and malloc in C?

618


Why is this loop always executing once?

625






What does %c mean in c?

662


what is uses of .net

1281


What is the advantage of using #define to declare a constant?

629


How important is structure in life?

600


What is the use of bitwise operator?

699


What are the types of pointers in c?

542


main(){char *str;scanf("%s",str);printf("%s",str); }The error in the above program is: a) Variable 'str' is not initialised b) Format control for a string is not %s c) Parameter to scanf is passed by value. It should be an address d) none

737


What is the difference between malloc() and calloc() function in c language?

614


What is a lvalue

670


What is a example of a variable?

561