7.26.2012

Number pyramid

Q. Write a C program to print the following number structure:


          1
         2 2
        3 3 3
       4 4 4 4
      5 5 5 5 5
     6 6 6 6 6 6


Ans.


/*c program for print the following number triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int r,c,sp,n=6;
 for(r=1; r<=6; r++)
 {
  for(sp=1; sp<=n; sp++)
     printf(" ");
  for(c=1; c<=r; c++)
  {
     printf("%d",r);
     printf(" ");
  }
  printf("\n");
  n=n-1;
 }
 getch();
 return 0;
}


/************Output************/


Output of number pyramid C program
Screen shot for number triangle C program

12 comments:

  1. Replies
    1. what is wrong in above program?

      This program is executed successfully and produced output.

      Delete
  2. plz tell the algorithm formed in this pyramid
    *
    * *
    * * *
    * * * *

    ReplyDelete
    Replies
    1. Algorithm and program for above star pyramid at:

      http://cprogrammingcodes.blogspot.in/2012/10/algorithm-for-star-pyramid.html

      Delete
  3. please
    *
    **
    ***
    ****
    *****
    ******

    ReplyDelete
    Replies
    1. @Ahmed,

      Your required above program source code at:

      http://cprogrammingcodes.blogspot.in/2013/04/star-sequence-pyramid.html

      Delete
  4. write a program to get o/p in this format

    0 4 4 4 4 4
    1 1 3 3 3 3
    2 2 2 2 2 2
    3 3 3 3 1 1
    4 4 4 4 4 0

    ReplyDelete
  5. this program is not executing :(

    ReplyDelete
  6. i want make this program in c++
    011235813...............
    means addition all time when we add 1 1 it becomes 2 when we add 3 in it will become 8 when we add 5 or 8 it will 13 to 100.please help me

    ReplyDelete
    Replies
    1. The series which you want is called Fibonacci Series and flowchart for this is given at : http://cprogrammingcodes.blogspot.in/2012/11/flowchart-for-fibonacci-series.html
      The program is given at http://cprogrammingcodes.blogspot.in/2011/09/fibonacy-series-c-program.html
      and program using recursion is at :
      http://cprogrammingcodes.blogspot.in/2012/08/generate-fibonacci-series-using.html

      Delete
  7. How about this pattern??

    4
    4 3 4
    4 3 2 3 4
    4 3 2 1 2 3 4
    4 3 2 3 4
    4 3 4
    4

    pls.. answer this As soon as possible.. thank you.. :)

    ReplyDelete
  8. Write a C program to find the value of sin (x) using the series..
    up to N terms accuracy without using the user defined function of sin(x).

    output:
    Enter value of x (in degress): 45
    Enter number of terms (N): 6
    The value of sin 45 with 6 terms accuracy is equal to 0.707.


    Write a C program to find the value of cos (x) using the series
    ⋯ ⋯ up
    to N terms accuracy without using the user defined function of cos(x).

    output:
    Enter value of x (in degress): 30
    Enter number of terms (N): 6
    The value of cos 30 with 5 terms accuracy is equal to 0.866.

    help me pls...

    ReplyDelete