In this tutorial you will learn about the C Program to Print Consecutive Column Numbers in Right Triangle and its application with practical example.
C Program to Print Consecutive Column Numbers in Right Triangle
In this tutorial, we will learn to create a C program that will print Consecutive Column Numbers in Right Triangle in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- For loop in C programming.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input rows from the user. 3. Generating the Consecutive Row Numbers in Right Triangle pattern using. 4. Printing the square pattern. 5. End the program. |
Program description:-
In today’s program, we will first take the input rows from the user. Then we will print the Consecutive numbers from 1 to ending using the for a loop. Then we will print the right angle triangle pattern filled with the Consecutive Numbers.
The Consecutive pattern means the printing of data in a sequential format, one time it returns 1, and the next time 2 then 3, and so on. The Consecutive pattern triangle contains numbers from 1 to the satisfying point.
The below is an example of the right triangle pattern program code filled with Consecutive numbers in the Column.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/* ** C Program to Print Consecutive Column Numbers in Right Triangle ** */ #include <stdio.h> int main() { //declaring the required variables for the program. int i, j, rw, k = 1; //i = it will hold the integer value for the program //j = it will hold the integer value for the program //k = it will hold the integer value for the program //rw = it will hold the integer value for the input of program //Taking the input number of rows from the user. printf("Enter Right Triangle Consecutive Col Nums Pattern Rows = "); scanf("%d",&rw); /* Making the pattern using the c programming language containing consecutive Row Numbers in Right Triangle. */ printf("Consecutive Numbers in Right Triangle Column Pattern\n"); //loop to print the pattern triangle. for (i = 1; i <= rw; i++ ) { for (j = 1 ; j <= i; j++ ) { //printing the right triangle. printf("%d ", k++); } printf("\n"); } return 0; } |
Output:-
In the above program, we have last initialized the required variable.
- rw = it will hold the integer value.
- k = it will hold the integer value.
- j = it will hold the integer value.
- i = it will hold the integer value.
Input the number of rows for the pattern.
Code to make the print Consecutive Row Numbers in Right Triangle.
Printing Consecutive Row Numbers in Right Triangle.