Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What does c mean in basketball?

938


regarding pointers concept

1975


what is stack , heap ,code segment,and data segment

2631


How can I convert a number to a string?

1091


What’s a signal? Explain what do I use signals for?

1050


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

1058


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

1107


What is the value of a[3] if integer a[] = {5,4,3,2,1}?

1028


Why c language?

1005


Who invented bcpl language?

1116


What is identifiers in c with examples?

1116


What is the use of ?: Operator?

1079


Do you know pointer in c?

986


Why is this loop always executing once?

996


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 ].

1052