Floyd's triangle

Hollow triangle pattern in C programming

Hollow triangle patterns in C programming

In this tutorial, we will discuss How to create hollow triangle pattern in C programming language

We can print many types of  Floyd’s triangle pattern using nested for loop in C language

We describe four  hollow patterns in this post

Hollow triangle star patterns in C language

Pattern 1

Hollow triangle Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,rows;//variable declaration
    //Input row value from user
    printf("Enter of rows you want\n");
    scanf("%d",&rows);
    for(i=1; i<=rows; i++){//parent for loop
        for(j=i; j<=rows; j++){//print columns
            if(i==1 || j==i || j==rows){
                printf("*");
            }
            else{
                printf(" ");
            }
        }
        printf("\n");//move to next line
    }
    getch();
    return 0;
}

When the above code is executed, it produces the following results:

Hollow triangle pattern 1

Program 2

Hollow triangle pattern 2

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,rows;//variable declaration
    //Input row value from user
    printf("Enter of rows you want\n");
    scanf("%d",&rows);
    for(i=1; i<=rows; i++){//parent for loop, for row of hollow triangle
        for(j=1; j<=i; j++){//print columns
            if(j==1 || j==i || i==rows){
                printf("*");
            }
            else{
                printf(" ");
            }
        }
        printf("\n");//move to next line
    }
    getch();
    return 0;
}

When the above code is executed, it produces the following results:

Hollow triangle pattern 2

 

Program 3

Hollow triangle pattern 3

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,rows;//variable declaration
    printf("Enter the number of rows you want: ");
    scanf("%d",&rows);//get input from user for rows
    for(i=1; i<=rows; i++){
        for(j=1; j<i; j++){
            printf(" ");

        }
        for(j=i; j<=rows; j++){
            if(j==i || j==rows || i==1){
                printf("*");
            }
            else{
                printf(" ");
            }
        }
        printf("\n");//move to next line for iterate
    }
    getch();
    return 0;
}

 

Hollow triangle pattern 3

 

Program 4

Hollow triangle pattern 4

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,rows;
    printf("Enter the number of rows you want: ");
    scanf("%d",&rows);//get input from user for rows
    for(i=1; i<=rows; i++){
        for(j=i; j<rows; j++){
            printf(" ");//print space for triangle

        }
        for(j=1; j<=i; j++){
            if(i==rows || j==1 || j==i){
                printf("*");
            }
            else{
                printf(" ");
            }
        }
        printf("\n");//move to next line for iterate
    }
    getch();
    return 0;
}

When the above code is executed, it produces the following results:

Hellow triangle pattern 4

Suggested for you

For loop in C++ language

For loop in Java language

For loop in C language

For loop in Python language

Nested for loop in Java language

Nested for loop in C++ language

Nested for loop in C language

Nested for loop in Python language

Floyd’s triangle number pattern using for loop in C

Floyd’s triangle pattern using nested for loop in Java

Floyd’s triangle pattern using nested while loop in Java

C program to triangle number pattern
C program to Floyd's triangle star pattern
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago