Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

[ask]pyramid number with loop

loop

  • Please log in to reply
2 replies to this topic

#1 nitediver

nitediver

    CC Newcomer

  • Just Joined
  • PipPip
  • 13 posts

Posted 13 October 2009 - 04:45 AM

#include<stdio.h>
main()
{
int a,b,c;
clrscr();
 printf("input : ");scanf("%d",&c);
	for(a=1; a<=c; a++)
	{
		for(b=1; b<=a; b++)
			printf("%d",b);
			printf("\n");
	}
getch();
}

Output :
1
12
123

I try to make it like this:

1
12
123
12
1

but i always get this :

1
3
12
3
123
3
  • 0

#2 veda87

veda87

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 126 posts

Posted 13 October 2009 - 05:40 AM

Modified code:
#include<stdio.h>
int main()
{
int a,b,c;
printf("input : ");
scanf("%d",&c);
	for(a=1; a<=c; a++) {
		for(b=1; b<=a; b++)
			printf("%d",b);
		printf("\n");
	}
	for( a=(c-1); a > 0; a--) {
		for(b=1; b<=a;b++)
			printf("%d",b);
		printf("\n");			

	}
}

  • 0

#3 nitediver

nitediver

    CC Newcomer

  • Just Joined
  • PipPip
  • 13 posts

Posted 13 October 2009 - 05:57 AM

thanks a lot veda...
thats work...
  • 0





Also tagged with one or more of these keywords: loop

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download