C program to print rhombus star pattern

  • Write a program in C to print rhombus star pattern using for loop.
  • Write a C program to print a rhombus star pattern of n rows using loops.
For a rhombus star pattern of 6 rows. Program's output should be:
******
 ******
  ******
   ******
    ******
     ******

Required Knowledge

Algorithm to print rhombus star pattern using loop
  • We first take the number of rows(N) in the pattern as input from user using scanf function.
  • Each row of rhombus star pattern contains N star characters.
  • Each row R, contains R-1 space characters followed by N star characters.
  • One iteration of outer for loop will print one row at a time.
  • First inner for loop prints space characters whereas second inner for loop prints star characters.

C program to print rhombus star pattern

#include <stdio.h>  
  
int main() {  
    int i,j, rows;
    
    printf("Enter the number of rows\n");
    scanf("%d", &rows);  
  
    for(i = 1; i <= rows; i++) {  
        /* Print spaces before stars in a row */  
        for(j=i; j<rows; j++) {  
            printf(" ");  
        }  
  
        /* Print rows stars after spaces in a row */  
        for(j = 1; j <= rows; j++) {  
            printf("*");  
        }  
  
        /* jump to next row */  
        printf("\n");  
    }  
  
    return 0;  
}
Output
Enter the number of rows
6
******
 ******
  ******
   ******
    ******
     ******

Related Topics
C program hollow diamond star pattern
C program pyramid star pattern
C program rectangle star pattern
C program hollow pyramid star pattern
C program square star pattern
C program hollow rectangle pattern
C program mirrored right triangle star pattern
C program prime number triangle pattern
C program multiplication table triangle pattern
List of all C pattern programs