- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to print the stars in Diamond pattern using C language?
Here, to print stars in diamond pattern, we are using nested for loops.
The logic that we use to print stars in diamond pattern is shown below −
//For upper half of the diamond the logic is: for (j = 1; j <= rows; j++){ for (i = 1; i <= rows-j; i++) printf(" "); for (i = 1; i<= 2*j-1; i++) printf("*"); printf("
"); }
Suppose let us consider rows=5, it prints the output as follows −
* *** ***** ******* *********
//For lower half of the diamond the logic is: for (j = 1; j <= rows - 1; j++){ for (i = 1; i <= j; i++) printf(" "); for (i = 1 ; i <= 2*(rows-j)-1; i++) printf("*"); printf("
"); }
Suppose row=5, the following output will be printed −
******* ***** *** *
Example
#include <stdio.h> int main(){ int rows, i, j; printf("Enter no of rows
"); scanf("%d", &rows); for (j = 1; j <= rows; j++){ for (i = 1; i <= rows-j; i++) printf(" "); for (i = 1; i<= 2*j-1; i++) printf("*"); printf("
"); } for (j = 1; j <= rows - 1; j++){ for (i = 1; i <= j; i++) printf(" "); for (i = 1 ; i <= 2*(rows-j)-1; i++) printf("*"); printf("
"); } return 0; }
Output
Enter no of rows 5 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- Related Articles
- Program to print Diamond Pattern in C
- Program to print Inverse Diamond pattern on C++
- C Program to print hollow pyramid and diamond pattern
- Program to print hollow pyramid and diamond pattern in C++
- How to print the pattern of stars in JShell in Java 9?
- Java Program to Print Diamond Star Pattern
- Swift program to Print Diamond Star Pattern
- Golang Program To Print Diamond Star Pattern
- Java program to print a given pattern. (stars)
- Java Program to Print Half Diamond Star Pattern
- Swift Program to Print Half Diamond Star Pattern
- Swift program to Print Half Diamond Numeric Pattern
- Golang Program to Print Half Diamond Star Pattern
- Swift Program to Print half Diamond Binary Pattern
- How to print a diamond using nested loop using C#?

Advertisements