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 / vignesh1988i
DIFFERENT LOGIC
#include<stdio.h>
#include<conio.h>
void main()
{
int m,n,p;
printf("enter the limit value");
scanf("%d",&m);
n=m+1;
for(int i=1;i<2*m-1;i++)
{
if(i<=m)
{
n--;
p=0;
}
else
{
n++
p=1;
}
if(i%2==p)
{
for(int j=1;j<n;j++)
printf("%d",j);
}
else
{
for(j=n;j>=1;j--)
printf("%d",j);
}
}
getch();
}
| Is This Answer Correct ? | 0 Yes | 3 No |
Post New Answer View All Answers
What does c mean in basketball?
regarding pointers concept
what is stack , heap ,code segment,and data segment
How can I convert a number to a string?
What’s a signal? Explain what do I use signals for?
What does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file
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 the value of a[3] if integer a[] = {5,4,3,2,1}?
Why c language?
Who invented bcpl language?
What is identifiers in c with examples?
What is the use of ?: Operator?
Do you know pointer in c?
Why is this loop always executing once?
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].