Table of Contents
Floyd’s triangle number Pattern in C Language using for loop
In this article, we will discuss Floyd’s triangle number Pattern in C Language using for loop
In this post, we are going to learn how to create Floyd’s triangle number pattern using for loop
Triangle number Pattern 1
Program 1
#include <stdio.h>
#include <stdlib.h>
int main()
{
int rowNum,row,coloum;
printf(“Enter the randomrow numbern”);
scanf(“%d”,&rowNum);
for(row=1; row<=rowNum; row++){
for(coloum=1; coloum<=row; coloum++){
printf(“%d”,coloum);
}
printf(“n”);
}
return 0;
}
Triangle number Pattern 2
Program 2
#include <stdio.h>
#include <stdlib.h>
int main()
{
int rowNum,row,coloum;
printf(“Enter the randomrow numbern”);
scanf(“%d”,&rowNum);
for(row=1; row<=rowNum; row++){
for(coloum=1; coloum<=row; coloum++){
printf(“%d”,row);
}
printf(“n”);
}
return 0;
}
Triangle number Pattern 3
Program 3
#include <stdio.h>
#include <stdlib.h>
int main()
{
int rowNum,row,coloum,no=0;
printf(“Enter the randomrow numbern”);
scanf(“%d”,&rowNum);
for(row=1; row<=rowNum; row++){
for(coloum=1; coloum<=row; coloum++){
no++;
printf(“%d”,no);
}
printf(“n”);
}
return 0;
}
Triangle number Pattern 4
Program 4
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,space,rows,k=0, count=0,count1=0;
printf(“Enter number of rows:n”);
scanf(“%d”,&rows);
for(i=1; i<=rows; ++i)
{
for (space=1; space<=rows-i; ++space)
{
printf(” “);
++count;
}
while(k!=2*i-1)
{if(count<=rows-1)
{
printf(“%d”,i+k);
++count;
}
else
{
++count1;
printf(“%d”,(i+k-2*count1));
}
++k;
}
count1=count=k=0;
printf(“n”);
}
return 0;
}
Related Article
Suggested for you