Jump to content

[ask]pyramid number with loop

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
nitediver

nitediver

    Newbie

  • Members
  • PipPip
  • 14 posts

#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

#2
veda87

veda87

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
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");			


	}

}


#3
nitediver

nitediver

    Newbie

  • Members
  • PipPip
  • 14 posts
thanks a lot veda...
thats work...