In this tutorial ,we will learn about triangle Number pattern using nested while in C.
We can use nested while loop in C to write coding for Squares, rectangles, Floyed triangle ,Pyramid triangles and many other shapes.
In this tutorial, we will learn about Floyd’s triangle shapes and how to write coding for that, in the C programming language.
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int i=1; while(i<=10){//outer while loop int j=1; while(j<=i){//inner while loop printf("%d",j);//display on the screen j++; } printf("\n");//move to next line i++; } getch(); return 0; }
When the above code is compiled and executed, it produces the following results
1 12 123 1234 12345 123456 1234567 12345678 123456789 12345678910
Program 2
#include <stdio.h> #include <stdlib.h> int main() { int i=1; while(i<=9){//outer while loop int j=1; while(j<=i){//inner while loop printf("%d",i);//display on the screen j++; } printf("\n");//move to next line i++; } return 0; }
When the above code is compiled and executed, it produces the following results
1 22 333 4444 55555 666666 7777777 88888888 999999999
Program 3
#include <stdio.h> #include <stdlib.h> int main() { printf("floyd's triangle number pattern\n"); printf("Enter the number of rows: \n"); int rows; scanf("%d",&rows);//takes input from user int row=1; printf("Here your pattern \n\n"); int i=1; while(i<=rows){//inner wile loop int j=1; while(j<=i){//outer while loop printf("%d",row); row++; j++; } printf("\n");//move to next line i++; } getch(); return 0; }
When the above code is compiled and executed, it produces the following results
floyd's triangle number pattern Enter the number of rows: 6 Here your pattern 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Program 4
#include <stdio.h> #include <stdlib.h> int main() { printf("floyd's triangle number pattern\n\n"); int i=1,j,k,m1=10,num=0; while(i<=m1){ int k=1; while(k<=m1-(m1-i)){ printf(" "); k++; } num=m1-i; j=1; while(j<=num){ printf("%d",m1-(m1-j)); j++; } i++; printf("\n");//move to next line } getch(); return 0; }
When the above code is compiled and executed, it produces the following results
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
Similar post
Java program to print star pyramid pattern
C program to print star pyramid pattern
C++ program to print star pyramid pattern
Python program to print star pyramid pattern
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
Hollow pyramid triangle pattern in C++ language
Rhombus pattern in Java using for loop
Rhombus pattern in C using while loop
Rhombus pattern in C++ using do-while loop
Suggested for you
Do-while loop in Java language
Nested for loop in Java language
Nested for loop in C++ language
Nested for loop in Python language
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…