C Pyramid Program

1
1 2 2
1 2 2 3 3
1 2 2 3 3 4 4
how to create this pyramid using c

Showing Answers 1 - 13 of 13 Answers

jayasri lakshmi

  • Jul 24th, 2011
 

Code
  1.  

  2.  

  3. #include<stdio.h>

  4. main()

  5. {

  6.   int i,j,c;

  7.  for(i=1;i<=4;i++)

  8.  {

  9.     c=0;

  10.     for(j=1;j<=i;j++)

  11.     {

  12.        printf("%d",j);

  13.         if(c>=1)

  14.        printf("%d",j);

  15.       c++;

  16.     }

  17.   printf("

  18. ");

  19. }

  20. }

  Was this answer useful?  Yes

Pyramid is answered in following code

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. main()

  4. {

  5. int i,j;

  6. clrscr();

  7. for(i=1;i<=4;i++)

  8. {

  9.  for(j=1;j<=i;j++)

  10.  {

  11.   printf("%d    ",j);

  12.   if(j!=1)

  13.   printf("%d    ",j);

  14.  }


  15. ");

  16. }

  17. getch();

  18. }

  Was this answer useful?  Yes

varun pujara

  • Jun 18th, 2014
 

1 12 123 1234

  Was this answer useful?  Yes

Andy

  • Nov 4th, 2017
 

Code
  1. #include <iostream>

  2. using namespace std;

  3.  

  4. int main() {

  5.         for(int i=1;i<=4;i++){

  6.             for(int j=1;j<=i;j++)

  7.             if(j==1){

  8.                 cout <<j;        

  9.             }

  10.             else

  11.                 cout <<j<<j;

  12.        

  13.             cout<<endl;

  14.         }

  15.        

  16.         return 0;

  17. }

  Was this answer useful?  Yes

Arun

  • Nov 9th, 2017
 

#include "stdio.h"
#include "conio.h"
void vd_g_printPyramid(int szOfPyramid)
{
int i;
int j;
for (i = 0; i < szOfPyramid; i++)
{
for (j = 0; j <= i; j++)
{
if (j == 0)
{
printf("%d", j+1);
}
else
{
printf("%d%d", j + 1, j + 1);
}
}
printf("
");
}
}
int main()
{
printf("
Hello World");
int i = 0;
printf("
Enter size of pyramid");
scanf_s("%d",&i);
vd_g_printPyramid(i);

_getch();
return 0;
}

Code
  1. #include "stdio.h"

  2. #include "conio.h"

  3.  

  4. void vd_g_printPyramid(int szOfPyramid)

  5. {

  6.         int i;

  7.         int j;

  8.         for (i = 0; i < szOfPyramid; i++)

  9.         {

  10.                 for (j = 0; j <= i; j++)

  11.                 {

  12.                         if (j == 0)

  13.                         {

  14.                                 printf("%d", j+1);

  15.                         }

  16.                         else

  17.                         {

  18.                                 printf("%d%d", j + 1, j + 1);

  19.                         }

  20.                 }

  21.                 printf("

  22. ");

  23.         }

  24. }

  25.  

  26. int main()

  27. {

  28.         printf("

  29. Hello World");

  30.         int i = 0;

  31.         printf("

  32. Enter size of pyramid");

  33.         scanf_s("%d",&i);

  34.         vd_g_printPyramid(i);

  35.        

  36.         _getch();

  37.         return 0;

  38. }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions