9.24.2011

Floyd's triangle

Q. Write a C program to floyd algorithm number triangle in C as:

  1
  2 3
  4 5 6
  7 8 9 10

Ans. 

/* c program for floyd algorithm number triangle */
#include<stdio.h>
int main()
{
 int r,c,n,x=1;
 printf("Enter No. Of rows : ");
 scanf("%d", &n);
 for(r=1; r<=n; r++)
 {
   for(c=1; c<=r; c++,x++)
       printf(" %d",x);
   printf("\n");
 }
 getch();
 return 0;
}

/*************************************************************
The output of above program would be:
**************************************************************/

Output of Floyd algorithm number triangle C program
Figure: Screen shot for Floyd algorithm number triangle C program

You might also like to read:


      A
      B C
      D  E  F
      G  H  I J


      9
      8  7
      6  5  4
      3  2  1  0 
         

     1
     2  3
     4  5  6
     7  8  9  10
     4  5  6
     2  3
     1

18 comments:

  1. #include

    void main()
    {
    int i, j, k, x = 1;
    for(i = 1; i <= 4; i++)
    { for(j = 1; j <= 4 - i; j++)
    printf(" ");
    for(k = 1 ; k <= i; k++, x++)
    printf("%d ", x);
    printf("\n");
    }


    }

    ReplyDelete
  2. algorithms and flowcharts for 31 lab programs

    ReplyDelete
  3. Can you please give the same program but in the form:
    a
    b c
    d e f
    g h i j k

    ReplyDelete
    Replies
    1. @Maya,

      //Your required program as:

      #include"stdio.h"
      int main()
      {
      int n=4,x='a';
      char r,c;
      for(r='a'; n>=1; n--,r++)
      {
      for(c='a'; c<=r; c++,x++)
      printf(" %c",x);
      printf("\n");
      }
      getch();
      return 0;
      }

      Delete
  4. Can you please give the same program but in the form:
    0 1 2 3 4
    1 2 3 4
    2 3 4
    3 4

    ReplyDelete
    Replies
    1. #include
      void main()
      {
      int i,j,n;
      int x=0,y=0;
      printf("Enter the no of line");
      scanf("%d",&n);
      for(i=0;i<=n;i++)
      {
      x=y;
      for(j=i;j<=n;j++,x++)
      printf("%d ",x);
      y++;
      printf("\n");
      }}

      Delete
  5. C program to print the pyramid of digits

    ReplyDelete
  6. print new line should come out of for loop
    then only v ill get triangle

    ReplyDelete
  7. R
    RI
    RIZ
    RIZA
    RIZAL

    how about this,,
    just print without input .

    ReplyDelete
  8. if i enter 5
    5
    4 3
    2 1 0
    -----------------------------------------
    if i enter 16
    16
    15 14
    13 12 11
    10 9 8 7
    6 5 4 3 2

    ReplyDelete
    Replies
    1. # Mavuri Yasoda

      Your required above Floyd number pattern C program source code at:

      http://cprogrammingcodes.blogspot.com/2016/07/reverse-floyd-number-pattern-c-program.html

      Delete
  9. Can help me..writing same prog using while loop

    ReplyDelete
    Replies
    1. Mohd Imran,

      Your required Floyd Triangle C program using while loop source code as :

      #include"stdio.h"
      int main()
      {
      int r,c,n,x=1;
      printf("Enter No. Of rows : ");
      scanf("%d", &n);
      r=1;
      while(r<=n)
      {
      c=1;
      while(c<=r)
      {
      printf(" %d",x);
      c++;
      x++;
      }
      r++;
      printf("\n");
      }
      getch();
      return 0;
      }


      Hope its help you. Thanks for improving C language community.

      Delete
  10. Replies
    1. Your required above number pattern source code :

      http://cprogrammingcodes.blogspot.com/2011/09/10design-numbers-tringle-pyramid.html

      Delete
  11. Replies
    1. #Ambarish Banerjee

      Your required number pattern design c program source code :

      http://cprogrammingcodes.blogspot.com/2011/09/10design-numbers-tringle-pyramid.html

      Delete
  12. More formally, a triangular number counts the number of symmetric objects that fits in the form of an equilateral triangle. The sequence of all triangle numbers is: 1, 3, 6, 10, 15, 21, … As shown here all those numbers form perfect equilateral triangles. You can read this article to understand more about triangular numbers.
    Your mission, should you choose to accept it:

    Take an integer input from the user, print a list of all even triangular numbers less than or equal to the input number. Additionally, only for the largest even triangular number you found, you should print all (odd and even) triangle numbers in a shape of a triangle as illustrated below.
    01
    ** 03
    ** ** 06
    ** ** ** 10
    ** ** ** ** 15
    ** ** ** ** ** 21
    ** ** ** ** ** ** 28

    ReplyDelete