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 are the different types of control structures in programming?
What is pointer & why it is used?
what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above
What functions are used in dynamic memory allocation in c?
What is pass by reference in c?
What is a macro in c preprocessor?
What is a pointer in c?
What is hash table in c?
if a is an integer variable, a=5/2; will return a value a) 2.5 b) 3 c) 2 d) 0
What is operator promotion?
Is c procedural or object oriented?
Write a program to print factorial of given number without using recursion?
What is getch() function?
What is meant by initialization and how we initialize a variable?
What is putchar() function?