codescracker


c

C Program to Print Floyd Triangle



« Previous Program Next Program »


Print Floyd Triangle in C

To print Floyd's triangle in C programming, use two for loops, the outer for loop is responsible for rows and the inner for loop is responsible for columns to print Floyd's triangle. Following is the simple Floyd's Triangle :

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

C Programming Code to Print Floyd's Triangle

Since Floyd’s triangle is a right angled-triangle using the natural numbers, so the following C program ask to the user to enter the range (upto how many line he or she want to print the Floyd's triangle) to print the Floyd's Triangle upto the given range:

/* C Program - Print Floyd's Triangle */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	int range, i, j, k=1;
	printf("Enter the range (upto how many line ?) : ");
	scanf("%d",&range);
	printf("\nFloyd's Triangle :\n");
	for(i=1; i<=range; i++)
	{
		for(j=1; j<=i; j++, k++)
		{
			printf("%d ",k);
		}
		printf("\n");
	}
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program print floyd triangle

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test