Announcement:

This is just the beginning of this blog, please don't copy any of my posts.

Saturday 7 September 2013

C Program to Print Floyds Triangle with Simple Example and Explanation

Floyd's triangle lists the natural numbers in a right triangle aligned to the left where
the first row is just 1
successive rows start towards the left with the next number followed by successive naturals listing one more number than the line above.
The first few lines of a Floyd triangle looks like this:
 1
 2  3
 4  5  6
 7  8  9 10
11 12 13 14 15
Program

#include<stdio.h>
#include<stdio.h>
void main()
{
int i,j,n,num;
clrscr();
printf("How many lines to print");
scanf("%d",&n);
num=1;
for(i=0;i<n;i++)
{
          for(j=0;j<=i;j++)
{
 printf("\t%d",num++);
 }
 printf("\n");
 }
 getch();
 }

Output:

How many lines to print
4

1  
2   3
4   5   6
7   8   9  10
Share it Please

Pankaj Gaikar

Pankaj Gaikar is a professional blogger from Pune, India who writes on Technology, Android, Gadgets, social media and latest tech updates at Punk Tech , Being Android & Shake The Tech . Email me HERE

0 comments :

Post a Comment

Copyright @ 2013 Pune University Bachelor of Engineering . Designed by Pankaj Gaikar | Love for The Tricks Machine