Floyd's triangle

Hollow Triangle Pattern using nested while loop in C

Hollow Triangle Pattern using nested while loop in C

In this tutorial, we will discuss a concept of Hollow Triangle Pattern using nested while loop in C

In this program, we are going to learn about how to display  Hollow Tringle star pattern using nested while loop in C programming  language

Here, we display some Hollow triangle Pattern program with coding using nested while loop and also program get input from the user using scanf() function in C  programming language

The user can provide numbers as they wish and get this pattern according to their input.

Floyd’s triangle star pattern 1

Program 1

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

int main()
{
    int i,j,rows;
    printf("Enter the number of rows\n");
    scanf("%d",&rows);
    i=1;
    while(i<=rows){//outer while loop
        j=1;
        while(j<=i){//inner for loop
        printf(" ");//print initial space

    if(j==1 || j==i ||i==rows )
        printf("*");//print star
    else
        printf(" "); //print inside space
    j++;;
}
i++;
printf("\n");//Move to the next line for print
    }
    return 0;
}

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

Floyd’s Triangle Pattern

Floyd’s triangle star pattern 2

Program 2

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

int main()
{
    int i,j,rows;
    printf("Enter the number of rows\n");
    scanf("%d",&rows);
    i=1;
    while(i<=rows){..outer for loop
        j=i;
        while(j<rows){
        printf(" ");//print space
        j++;
        }
        j=1;
        while(j<=i){

    if(j==i || j==1 ||i==rows )
        printf("*");//print star
    else
        printf(" ");//print space
    j++;;
        }
        i++;
printf("\n");//Move to the next line for print
}
getch();
    return 0;
}

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

Floyd’s Triangle Pattern

Floyd’s triangle star pattern 3

Program 3

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

int main()
{
    int i,j,rows;
    printf("Enter the number of rows\n");
    scanf("%d",&rows);
    i=1;
    while(i<=rows){//outer for loop
        j=1;
        while(j<=rows){//inner for loop

    if(j==i || j==rows ||i==1 )
        printf("*");//print star
    else
         printf(" ");//print space
    j++;;
        }
        i++;
printf("\n");//Move to the next line for print
}
getch();
    return 0;
}

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

Floyd’s Triangle Pattern

Floyd’s triangle star pattern 4

Program 4

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

int main()
{
    int i,j,rows;
    printf("Enter the number of rows\n");
    scanf("%d",&rows);
    i=1;
    while(i<=rows){//outer for loop
        j=i;
        while(j<=rows){//inner for loop

    if( i==1|| j==i || j==rows)
        printf("*");//print star
    else
        printf(" ");//print space
    j++;;
        }
        i++;
printf("\n");//Move to the next line for print
}
getch();
    return 0;
}

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

Floyd’s Triangle Pattern

Suggested for you

Operator in C language

Datatype in C language

While loop in C language

Nested while loop in C language

 

Hollow Pyramid Pattern in C using nested while
Program to Double pyramid star pattern in C++
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

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago