C program to print exponentially increase star pattern

  • Write a program in C to print right triangle star (*) pattern of n rows using for loop.
  • Write a C program to print a right angles triangle pattern of star (*) character using loops.
For a exponentially increasing star pattern. Program's output should be:
*
**
****
********
****************

Required Knowledge

Algorithm to print exponentially increasing star pattern using loop
  • Take the number of rows(N) of right triangle as input from user using scanf function.
  • Number of stars in Kth row is equal to 2K. 0th row contains 1 star, 1st row contains 2 stars, 3rd row contains 3 stars. In general, Kth row contains 2K stars.
  • We will use two for loops to print exponential star pattern.
    • For a exponentially increasing star pattern of N rows, outer for loop will iterate N time. Each iteration of outer loop will print one row of the pattern.
    • For Kth row of pattern, inner loop will iterate 2k times. Each iteration of inner loop will print one star (*).

C program to print exponentially increasing star pattern

#include<stdio.h> 
#include<math.h>

int main(){
    int i,j,rows;
    printf("Enter the number of rows\n");
    scanf("%d", &rows);
    
    for(i = 0; i < rows; i++){
     /* Prints one row of pattern */
       for(j = 0; j < pow(2,i); j++){
           printf("*");
       }
       /* move to next row */
       printf("\n");
    }
    return 0;
}
Output
Enter the number of rows
4
*
**
****
********
****************

Related Topics
C program right triangle star pattern
C program rectangle star pattern
C program diamond star pattern
C program reversed pyramid star pattern
C program hut star pattern
C program multiplication table triangle pattern
C program heart shape star pattern
C program palindrome triangle pattern
C program prime number triangle pattern
List of all C pattern programs