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
Whats s or c mean?
What is void main ()?
What is your stream meaning?
Explain the difference between call by value and call by reference in c language?
How can I ensure that integer arithmetic doesnt overflow?
What are register variables? What are the advantage of using register variables?
Define circular linked list.
What is pointers in c?
write a program to print largest number of each row of a 2D array
What is the meaning of && in c?
Explain how do you list a file’s date and time?
How many bytes are occupied by near, far and huge pointers (dos)?
a direct address that identifies a location by means of its displacement from a base address or segment a) absolute address b) relative address c) relative mode d) absolute mode
How can I read a binary data file properly?
Can you assign a different address to an array tag?