Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C
  • C Basics
  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Arrays
  • C Strings
  • C Pointers
  • C Preprocessors
  • C File Handling
  • C Programs
  • C Cheatsheet
  • C Interview Questions
  • C MCQ
  • C++
Open In App
Next Article:
Program to print Kite Pattern
Next article icon

C Program To Print Diamond Pattern

Last Updated : 10 Dec, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The Diamond Pattern is a symmetrical shape where the number of characters increases up to the centre and then decreases forming a diamond-like structure. It can be visualized as a full pyramid and an inverted full pyramid joined by their bases. In this article, we will learn how to print the Diamond Pattern using C program.

Diamond-Pattern

Program To Print Diamond Pattern

Star Pattern
#include <stdio.h>  int main() {     int n = 5;      // First outer loop to iterator through each row     for (int i = 0; i < 2 * n - 1; i++) {          // Assigning values to the comparator according to         // the row number         int comp;         if (i < n) comp = 2 * (n - i) - 1;         else comp = 2 * (i - n + 1) + 1;          // First inner loop to print leading whitespaces         for (int j = 0; j < comp; j++)             printf(" ");          // Second inner loop to print stars *         for (int k = 0; k < 2 * n - comp; k++) {             printf("* ");         }         printf("\n");     }     return 0; } 
Number Pattern
#include <stdio.h>  int main() {     int n = 5;      // First outer loop to iterator through each row     for (int i = 0; i < 2 * n - 1; i++) {          // Assigning values to the comparator according to         // the row number         int comp;         if (i < n) comp = 2 * (n - i) - 1;         else comp = 2 * (i - n + 1) + 1;          // First inner loop to print leading whitespaces         for (int j = 0; j < comp; j++)             printf(" ");          // Second inner loop to print stars *         for (int k = 0; k < 2 * n - comp; k++) {             printf("%d ", k + 1);         }         printf("\n");     }     return 0; } 
Alphabet Pattern
#include <stdio.h>  int main() {     int n = 5;      // First outer loop to iterator through each row     for (int i = 0; i < 2 * n - 1; i++) {          // Assigning values to the comparator according to         // the row number         int comp;         if (i < n) comp = 2 * (n - i) - 1;         else comp = 2 * (i - n + 1) + 1;          // First inner loop to print leading whitespaces         for (int j = 0; j < comp; j++)             printf(" ");          // Second inner loop to print stars *         for (int k = 0; k < 2 * n - comp; k++) {             printf("%c ", k + 'A');         }         printf("\n");     }     return 0; } 


Output

        *           |           1           |           A
* * * | 1 2 3 | A B C
* * * * * | 1 2 3 4 5 | A B C D E
* * * * * * * | 1 2 3 4 5 6 7 | A B C D E F G
* * * * * * * * * | 1 2 3 4 5 6 7 8 9 | A B C D E F G H I
* * * * * * * | 1 2 3 4 5 6 7 | A B C D E F G
* * * * * | 1 2 3 4 5 | A B C D E
* * * | 1 2 3 | A B C
* | 1 | A

Explanation:

  • Outer loop iterates through each row from 0 to 2 * n – 2 (as total 2 * n – 1 rows).
  • comp determines the number of leading spaces based on the current row number.
    • For the first half (i < n): comp = 2 * (n – i) – 1.
    • For the second half (i >= n): comp = 2 * (i – n + 1) + 1.
  • First inner loop prints leading white spaces in each row.
  • Second inner loop iterates through the columns in the row to print * star.
  • After completing a row, printf(“\n”) moves to the next line.


Next Article
Program to print Kite Pattern
author
mukulsomukesh
Improve
Article Tags :
  • C Language
  • C Programs
  • C Pattern Programs

Similar Reads

  • C Program To Print Hollow Diamond Pattern
    The Hollow Diamond Pattern is a variation of the diamond pattern where only the edges of the diamond are filled with characters and the inside remains empty. This creates a hollow effect in the shape of a diamond. In this article, we will learn how to print the Hollow Diamond Pattern using C program
    4 min read
  • C program to print name pattern
    The printing of patterns is the most common and interesting problem. This C program prompts users to input their names and transform each letter of the name into a visually appealing big star pattern. For Example, Input: NAME Output: * * **** * * ****** ** * * * ** ** * * * * ****** * ** * **** * **
    5 min read
  • C Program to Print Number Pattern
    A number pattern involves printing numbers in a specific arrangement or shape, often in the form of a pyramid, triangle, or other geometric shapes. They are great for practicing loops and conditional statements. In this article, we will learn how to print different number patterns in C. Rhombus Numb
    6 min read
  • Program to print Kite Pattern
    The task is to draw a KITE pattern using '$' Example: Output: $ $$$ $$$$$ $$$$$$$ $$$$$$$$$ $$$$$$$ $$$$$ $$$ $ $$$ $$$$$ Below is the code to implement the above problem: Program: C/C++ Code // C++ Program to print Kite Pattern #include <bits/stdc++.h> #include <stdlib.h> using namespac
    8 min read
  • C Program to Print Hourglass Pattern
    The Hourglass Pattern is a symmetrical pattern similar to an hourglass shape. It can be visualized as an inverted full pyramid placed on a regular full pyramid. In this article, we will learn how to print the Hourglass Pattern using a C program. Program to Print Hourglass Pattern in C[GFGTABS] Star
    4 min read
  • C Program to Print Cross or X Pattern
    The Cross or X Pattern is a pattern where characters or stars are printed diagonally from top-left to bottom-right and from top-right to bottom-left, forming an "X" shape. In this article, we will learn how to print this pattern using a C program. Program to Print Cross or X Pattern[GFGTABS] Star Cr
    3 min read
  • Program to print numeric pattern
    Given the value of n i.e, the number of rows, print the following pattern. Examples : Input : n = 4 Output : 1 5 2 8 6 3 10 9 7 4 Input : n = 6 Output : 1 7 2 12 8 3 16 13 9 4 19 17 14 10 5 21 20 18 15 11 6 Approach: The approach is to start printing the pattern from the end of each row. After the c
    6 min read
  • C Program To Print Floyd Triangle Pattern
    Here, we will build a C Program To Print Floyd Triangle Pattern using 2 approaches i.e. Using for loop Using while loop Input: n = 5 Output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1. Using for loop The first for loop is used to iterate the number of rows and the second for loop is used to repeat the nu
    2 min read
  • Program to print the Cot Bed Pattern
    The given task is to draw the Cot Bed pattern using '$' Cot Bed Pattern: $$$$$$$$$$$$$$$$$$$$$$$$$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $$$$$$$$$$$$$$$$$$$$$$$$$ Below is the code to implement the above problem: Program: C/C++ Code // C++ program to print //
    10 min read
  • Program to print the given H Pattern
    Given an integer N, the task is to print the Alphabet H Pattern as given below: 1 N 2 * 3 3 * 2 N * 3 2 1 * 2 3 3 2 * 1 N Examples: Input: N = 3 Output: 1 3 2 2 3 2 1 2 2 1 3 Input: N = 4 Output: 1 4 2 3 3 2 4 3 2 1 3 2 2 3 1 4 Approach: Print the Left value and leave 2 * (index - 1) blank spaces
    7 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences