C Program to Print Rhombus Star Pattern

Here is a C program to print rhombus star pattern using for loop. The Rhombus Star Pattern Printing Program in C is a fascinating exercise that introduces beginners to geometric patterns and shapes. For a rhombus star pattern of 6 rows. Program's output should be:

C program rhombus pattern

Required Knowledge

Algorithm to print rhombus star pattern using loop
  • We first take the number of rows(N) as input from user using scanf function.
  • The index of rows and columns will start from 0.
  • Each row of rhombus star pattern contains N star characters.
  • Each iteration of outer for loop(from i = 0 to N-1) will print one row of pattern at a time.
  • Each jth row, contains j space characters followed by N star characters.
  • First inner for loop prints space characters whereas second inner for loop prints star characters.

Tips for Writing the Rhombus Star Pattern Printing Program in C

As you embark on the task of writing the Rhombus Star Pattern Printing Program in C, consider the following tips to help you successfully complete the program:
  • Understanding the Rhombus Shape : Before you start writing any code, it's important to understand the geometric properties of a rhombus. A rhombus is a quadrilateral with all four sides of equal length and opposite sides parallel to each other.

  • Using Nested Loops: To print the rhombus pattern, you'll need to use nested loops. The outer loop will control the number of rows, while the inner loop will control the number of stars printed in each row. Ensure that your loops are structured correctly to achieve the desired rhombus shape.

  • Calculating the Number of Stars : Since a rhombus has equal sides, you'll need to calculate the number of stars to be printed in each row based on the size of the rhombus. The number of stars in each row follows a specific pattern that you'll need to determine.

  • Handling Spaces : In addition to printing stars, you'll also need to print spaces to achieve the correct spacing between stars. Use conditional statements to determine when to print a space and when to print a star, based on the desired pattern of the rhombus.

  • Testing Incrementally : Start with a small rhombus pattern and gradually increase its size to test the program. This incremental testing approach will help you identify and fix errors early on, ensuring that your program behaves as expected.

  • Seeking Clarification : If you're unsure about any aspect of the rhombus pattern printing program, don't hesitate to seek clarification from your peers or instructors. Understanding the problem thoroughly is key to writing an effective solution.

Here is the matrix representation of the rhombus star pattern. The row numbers are represented by i whereas column numbers are represented by j.

C program rhombus pattern

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 = 0; i < rows; i++) {
        /* Print spaces before stars in a row */
        for (j = 0; j < i; j++) {
            printf(" ");
        }
        /* Print rows stars after spaces in a row */
        for (j = 0; 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