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
What is methods in c?
What is cohesion in c?
When is the “void” keyword used in a function?
Write the syntax and purpose of a switch statement in C.
What the different types of arrays in c?
What will the preprocessor do for a program?
Explain union. What are its advantages?
What are the advantages of Macro over function?
how many errors in c explain deply
What is the function of volatile in c language?
Why is python slower than c?
What are volatile variables in c?
Explain a file operation in C with an example.
What is a stream?
What is the difference between union and anonymous union?