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 extern c means?
What are pointers? What are different types of pointers?
Do you know the use of 'auto' keyword?
What are valid signatures for the Main function?
Is there any data type in c with variable size?
What are high level languages like C and FORTRAN also known as?
write a c program for swapping two strings using pointer
.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }
Why #include is used in c language?
Write a program to reverse a given number in c?
Explain why C language is procedural?
How are portions of a program disabled in demo versions?
what value is returned to operating system after program execution?
if (i = 0)printf ("True"); elseprintf("False"); Under what conditions will the above print out the string "True" a) Never b) Always c) When the value of i is 0 d) all of the above
What is pointers in c with example?