Program 6 - CSU1128P - CSE 2026 - Shoolini University

Program to print the rhombus of numbers of the range entered by the user. Example 3 = 3 2 1 2 3

Code

                    
/*
 * -----------------------------------------------------------
 * Logic Building with Computer Programming (CSU1128P)
 * Instructor: Abdullahi Adem | Author: Divya Mohan
 * 
 * This code is a part of the educational initiative by dmj.one
 * with aim of empowering and inspiring learners in the field of
 * Computer Science and Engineering through the respective courses.
 * 
 * (c) 2022, Divya Mohan for dmj.one. All rights reserved.
 * -----------------------------------------------------------
 */

#include <stdio.h>
int main()
{
    int d, m, j, o = 0, n;
    printf("\n\n Program to print the rhombus of numbers from the range entered by the user. Example 3 = 3 2 1 2 3 \n\n");

    printf("Enter a number for which you want to print its triangle and its reverse to form a rhombus (Example: 4 = 4 3 2 1 2 3 4) - and press enter: ");
    scanf("%d", &d);
    printf("\n Rhombus for the entered range %d is: \n", d);
    int q = d + 1;
    for (m = 0; m <= d; m++)
    {
        for (j = 1; j <= d - m; j++)
        {
            printf("  ");
        }
        for (o = 1; o <= m; o++)
        {
            printf(" %d", q - o);
        }
        for (int l = d - m; l <= d; l++)
        {
            printf(" %d", l);
        }
        printf("\n");
    }
    for (m = 1; m <= d; m++)
    { 
        for (j = 1; j <= m; j++)
        {
            printf("  ");
        }
        
        for (int l = d ; l >= m; l--)
        {
            printf(" %d", l);
        }
        for (o = 1; o <= d - m; o++)
        {
            printf(" %d", o + m);
        }
        printf("\n");
    }
    return 0;
}
                    
                

Output

Enter a number for which you want to print its triangle and its reverse to form a rhombus (Example: 4 = 4 3 2 1 2 3 4) - and press enter: 5
Rhombus for the entered range 5 is:

5
5 4 5
5 4 3 4 5
5 4 3 2 3 4 5
5 4 3 2 1 2 3 4 5
5 4 3 2 1 0 1 2 3 4 5
5 4 3 2 1 2 3 4 5
5 4 3 2 3 4 5
5 4 3 4 5
5 4 5
5