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
What is hash table in c?
Explain what is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
Ow can I insert or delete a line (or record) in the middle of a file?
What functions are used for dynamic memory allocation in c language?
Are there namespaces in c?
What is the difference between a free-standing and a hosted environment?
Why is it important to memset a variable, immediately after allocating memory to it ?
State the difference between realloc and free.
The number of bytes of storage occupied by short, int and long are a) 2, 2 and 4 b) 2, 4 and 4 c) 4, 4 and 4 d) none
What is #include stdio h and #include conio h?
"%u" unsigned integer print the a) address of variable b) value of variable c) name of a variable d) none of the above
What is nested structure with example?
How do you determine the length of a string value that was stored in a variable?
How can I delete a file?
How can I do serial ("comm") port I/O?