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 #include preprocessor?

768


What is the difference between declaring a variable by constant keyword and #define ing that variable?

2943


What are void pointers in c?

726


How can I write functions that take a variable number of arguments?

786


What are directives in c?

690






How do you generate random numbers in C?

839


5 Write an Algorithm to find the maximum and minimum items in a set of ā€˜nā€™ element.

1767


Hai sir, I had planned to write the NIC scientific engineer exam , plz post the sample question......

1909


What is a char c?

746


Badboy is defined who has ALL the following properties: Does not have a girlfriend and is not married. He is not more than 23 years old. The middle name should be "Singh" The last name should have more than 4 characters. The character 'a' should appear in the last name at least two times. The name of one of his brothers should be "Ram" Write a method: boolean isBadBoy(boolean hasGirlFriend , boolean isMarried, int age , String middleName , String lastName , String[] brotherName); isHaveGirlFriend is true if the person has a girlfriend isMarried is true if the person is married age is the age of the person middleName is the middle name of the person lastName is the last name of the person brotherName is the array of the names of his brothers

1598


When c language was developed?

781


Can we change the value of constant variable in c?

732


What is an auto keyword in c?

809


Can we use visual studio for c?

713


How pointers are declared?

685