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
Explain the difference between malloc() and calloc() in c?
What is time null in c?
What is meant by 'bit masking'?
How is null defined in c?
Can you please explain the scope of static variables?
write a c program for swapping two strings using pointer
What is a method in c?
What is a global variable in c?
I just typed in this program, and it is acting strangely. Can you see anything wrong with it?
What is the maximum length of an identifier?
What are variables and it what way is it different from constants?
Explain the ternary tree?
Differentiate between new and malloc(), delete and free() ?
What are # preprocessor operator in c?
what is recursion in C