print the following using nested for loop.
5 4 3 2 1
1 2 3 4
3 2 1
1 2
1
2 1
1 2 3
4 3 2 1
1 2 3 4 5
Answer Posted / dally
#include<stdio.h>
int main()
{
int i,j,n=5;
for(i=n;i>=1;i--)
{
if(i%2 == 0){
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
else
{
for(j=i;j>=1;j--)
printf("%d",j);
printf("\n");
}
}
for(i=2;i<=5;i++)
{
if(i%2 != 0) {
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
else
{
for(j=i;j>=1;j--)
printf("%d",j);
printf("\n");
}
}
}
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
Explain how does flowchart help in writing a program?
What is c programming structure?
how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions
What does char * * argv mean in c?
What are the similarities between c and c++?
What are reserved words with a programming language?
What is const volatile variable in c?
How many levels of pointers can you have?
How can I find out how much free space is available on disk?
Can you assign a different address to an array tag?
What is mean by data types in c?
What is the value of uninitialized variable in c?
What is the use of pragma in embedded c?
What is difference between arrays and pointers?
What are linker error?