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:
Pascal Triangle Program in C
Next article icon

C Program To Print Triangle

Last Updated : 02 Aug, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Here, we will see how to print a triangle using the C program

Input: 

5

Output:

*   * *   * * *   * * * *   * * * * *  

Approach: 

The approach is very simple. We just execute a nested loop, and only print characters when the inner loop is executed after that just change the line.

Example:

C




// C program to print a triangle
#include <stdio.h>
  
// Driver code
int main()
{
    int n = 6;
  
    // ith row has i elements
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            printf("*");
        }
        printf("\n");
    }
    return 0;
}
 
 
Output
*  **  ***  ****  *****  ******

Time Complexity: O(n2)

Auxiliary Space: O(1),  No extra Space is used.



Next Article
Pascal Triangle Program in C
author
mukulsomukesh
Improve
Article Tags :
  • C Language
  • C Programs
  • C Basic Programs

Similar Reads

  • 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 hollow Triangle pattern
    Given the number of lines as N, the task is to form the given hollow Triangle pattern.Examples: Input: N = 6 Output: ************ ***** ***** **** **** *** *** ** ** * * Approach: Input number of rows to print from the user as N.To iterate through rows run an outer loop from number of rows till it i
    6 min read
  • Pascal Triangle Program in C
    Pascal’s Triangle is a triangular array of numbers where each number is the sum of the two numbers directly above it. The triangle starts with 1 at the top, and each subsequent row contains the coefficients of binomial expansions. In this article, we will learn how to print Pascal's Triangle in C. P
    2 min read
  • C Program to Print Floyd's Triangle Pyramid Patterns
    Floyd’s triangle pyramid pattern is a pattern where numbers or characters are printed in a triangular shape, with each row containing an increasing number of consecutive integers or characters aligned to the left forming a shape similar to right half pyramid pattern. In this article, we will learn h
    2 min read
  • C Program To Print Your Own Name
    Printing your own name means displaying your name on the computer screen. In this article, we will learn how to print your own name using a C program. Examples Input: name = "Rahul"Output: RahulExplanation: The program prints "Rahul" to the screen. Input: name = "Vikas"Output: VikasExplanation: The
    4 min read
  • Your First C Program
    Like in most of the programming languages, program to write the text "Hello, World!" is treated as the first program to learn in C. This step-by-step guide shows you how to create and run your first C program. Table of Content Setting Up Your EnvironmentCreating a Source Code FileNavigating to the S
    5 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 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 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
  • C Program to Print Pyramid Pattern
    In C, a pyramid pattern consists of numbers, stars, or alphabets arranged in a triangular shape. In this article, we will learn how to print different shapes of pyramid patterns using C program. Following are the 6 common pyramid patterns: Right Half Pyramid PatternRight half pyramid pattern looks l
    13 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