
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
How to print Floyd’s triangle (of integers) using C program?
Floyd's triangle is a right-angle triangle of consecutive numbers, starting with a 1 in the top left corner −
For example,
1 2 3 4 5 6 7 8 9 10
Example 1
#include <stdio.h> int main(){ int rows, i,j, start = 1; printf("Enter no of rows of Floyd's triangle :"); scanf("%d", &rows); for (i = 1; i <= rows; i++){ for (j = 1; j <= i; j++){ printf("%d ", start); start++; } printf("
"); } return 0; }
Output
Enter no of rows of Floyd's triangle :6 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Example 2
The following program shows how to reverse a Floyd’s triangle −
#include<stdio.h> int main() { int num, i, j; printf("Enter number of rows: "); scanf("%d",&num); int k = num*(num+1)/2; for(i=num; i>=0; i--) { for(j=1; j<=i; j++) printf("%4d",k--); printf("
"); } return 0; }
Output
Enter number of rows: 7 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
- Related Articles
- Java Program to Display Floyd's Triangle
- How to print integers in the form of Pascal triangle using C?
- Floyd's triangle in PL/SQL
- Java program to print Pascal's triangle
- Java Program to Print Star Pascal's Triangle
- C# program to print duplicates from a list of integers
- Program to print Reverse Floyd’s triangle in C
- C++ Program to Print Right Triangle Star Pattern
- C++ Program to Print Left Triangle Star Pattern
- C++ Program to Print Upper Star Triangle Pattern
- C++ Program to Print Upward Triangle Star Pattern
- C++ Program to Print Downward Star Triangle Pattern
- Recursive program to print formula for GCD of n integers in C++
- C program to print area of triangle, square, circle, rectangle and polygon using switch case.
- C++ Program to Print Mirror Upper Star Triangle Pattern

Advertisements