You're online now.

Hurray! you are online now.

Floyd Triangle | Programs | Algorithm

A Floyd triangle is a right angled triangle consisting of consecutive natural numbers starting with one and then goind down through the rows.

For Example:
Define 5 rows Floys triangle.
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

Algorithm of Floyd Triangle

  1. Create variables that holds row and column values as i and j. Take a number to display the rows as number and set the varialbe k to 1 its initial value.
  2. Use Nested loop
  • Outer for loop starts its iteration i = 1 up to rows
  • Inner for loop starts its iteration from j = 1 up (j <-= i)
  1. Print the value of k.
  2. Increment the value of k by 1.
  3. And jump to the new line after each iteration of the inner loop.
  4. EXIT

Floyd triangle print in c program

#include <stdio.h>
    int main()
    {
       int row;
       printf("Enter the rows : ");
       scanf("%d", &row);
       int k=1;
       for(int i=1; i<=row; i++){
           for(int j=1; j<=i; j++){
               printf("%d ", k);
               k++;
           }
           printf("\n");
       }
        return 0;
    }
    

C++ program to print Floyd's Triangle

#include <iostream>
    using namespace std;
    int main()
    {
       int row;
       cout<<"Enter the rows : ";
       cin>>row;
       int k=1;
       for(int i=1; i<=row; i++){
           for(int j=1; j<=i; j++){
               cout<<k<<" ";
               k++;
           }
           cout<<endl;
       }
        return 0;
    }
    

Print Floyd's Triangle using while loop in c

#include <stdio.h>
    int main()
    {
       int row;
       printf("Enter the rows : ");
       scanf("%d", &row);
       int k=1, i = 1, j=1;
      while(i<=row){
          j = 1;
          while(j<=i){
              printf("%d ", k);
              k++;
              j++;
          }
          i++;
           printf("\n");
      }
        return 0;
    }
    

Print Floyd's triangle using while loop in c++

#include <iostream>
    using namespace std;
    
    int main()
    {
       int row;
       cout<<"Enter the rows : ";
       cin>>row;
       int k=1, i = 1, j=1;
       
      while(i<=row){
          j = 1;
          while(j<=i){
              cout<<k<<" ";
              k++;
              j++;
          }
          i++;
            cout<<endl;
      }
    
        return 0;
    }
    

Program to print the Floyd's triangle without natural number in c

#include <stdio.h>
    int main()
    {
       int row;
       printf("Enter the rows : ");
       scanf("%d", &row);
       for(int i=1; i<=row; i++){
           for(int j=1; j<=i; j++){
    	printf("* ");
           }
           printf("\n");
       }
        return 0;
    }
    

Print Floyd's Triangle without natural number in c++ proramming language

#include <iostream>
    using namespace std;
    
    int main()
    {
       int row;
       cout<<"Enter the rows : ";
       cin>>row;
       for(int i=1; i<=row; i++){
           for(int j=1; j<=i; j++){
    	cout<<"* ";
           }
           cout<<endl;
       }
        return 0;
    }
    
🖤 0
Buy me coffee ☕

Comments

Oops!

No comments here...