C program to print natural numbers in right triangle pattern

  • Write a program in C to print natural numbers in right triangle of n rows.
  • How to print a right triangle of natural numbers using for loops.
  • C program to print numbers from 1 to 10 in right triangle pattern.
For a right triangle of 4 rows. Program's output should be:
2 3
4 5 6
7 8 9 10

Required Knowledge

Algorithm to print natural number right triangle pattern using for loop
  • Take the number of rows(N) of right triangle as input from user using scanf function.
  • Number of integers in Kth row is always K. 1st row contains 1 integer, 2nd row contains 2 integers, 3rd row contains 3 integers and so on. In general, Kth row contains K integers.
  • We will use a integer counter to print consecutive natural numbers.
  • We will use two for loops to print right triangle of natural numbers.
    • Outer for loop will iterate N time. Each iteration of outer loop will print one row of the pattern.
    • For Kth row of right triangle pattern, inner loop will iterate K times. Each iteration of inner loop will increment the value of counter and print it on screen.

C program to print right triangle star pattern

int main() {
   int i, j, rows;
   int count = 1;
   printf("Enter the number of rows\n");
   scanf("%d", &rows);
   for (i = 1; i <= rows; i++) {
      for (j = 1; j <= i; j++) {
         printf("%d ", count);
Enter the number of rows
2 3
4 5 6
7 8 9 10

Related Topics
C program binary triangle pattern
C program prime number triangle pattern
C program palindrome triangle pattern
C program right triangle star pattern
C program inverted right triangle pattern
C program multiplication table triangle pattern
C program heart shape star pattern
C program pyramid star pattern
C program rhombus star pattern
List of all C pattern programs