Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Pyramid triangle number Pattern in C Language using for loop

Posted on December 2, 2016January 29, 2020

Table of Contents

  • Pyramid triangle number Pattern in C Language using for loop
    • Pyramid triangle number Pattern
      • Pyramid number Pattern 1
      • Pyramid number Pattern 2
      • Pyramid  number Pattern 3
      • Pyramid number Pattern 4
      • Related Article

Pyramid triangle number Pattern in C Language using for loop

In this tutorial, we will discuss the Pyramid triangle number Pattern in C Language using for loop

In the C Language, We can print various type of Pyramid shapes through nested for loop using number and special character

Pyramid triangle number Pattern

Pyramid number Pattern 1

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
int Noofrows;
printf("Enter number of rows to be printed!n");
scanf("%d",&Noofrows);

int row,colSpaces,colStar;
for(row=1; row<=Noofrows; row++)
{
for(colSpaces=Noofrows-row; colSpaces>=1; colSpaces--)
{
printf(" ");
}
for(colStar=1; colStar<=row; colStar++)
{
printf("%d ",row);
}
printf("n");
}
return 0;
}

When the above code is executed it produced the following result

Pyramid triangle number Pattern in C Language using for loop
Example 1

Pyramid number Pattern 2

Program 2

#include <stdio.h>
#include <stdlib.h>

int main()
{
int Noofrows;
printf("Enter number of rows to be printed!n");
scanf("%d",&Noofrows);

int row,colSpaces,colStar;
for(row=1; row<=Noofrows; row++)
{
for(colSpaces=Noofrows-row; colSpaces>=1; colSpaces--)
{
printf(" ");
}
for(colStar=1; colStar<=row; colStar++)
{
printf("%d ",colStar);
}
printf("n");
}
return 0;
}

When the above code is executed it produced the following result

Pyramid triangle number Pattern in C Language using for loop
Example 2

Pyramid  number Pattern 3

Program 3

#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,space,row,k,count,count1;
k=0;
count=0;
count1=0;

printf("Enter number of rowsn");
scanf("%d",&row);
for(i=1; i<=row; ++i)
{
for(space=1; space<=row-i; ++space){
printf(" ");
++count;
}
while(k != 2*i-1)
{
if(count<=row-1)

{
printf("%d",(i+k-2*count1));
}
else
{
++count1;
printf("%d",(i+k-2*count1));
}
++k;
}
count1=count=k=0;
printf("n");
}
return 0;
}

When the above code is executed it produced the following result

Pyramid triangle number Pattern in C Language using for loop
Example 3

Pyramid number Pattern 4

Program 4

#include <stdio.h>
#include <stdlib.h>

int main()
{
int i, space, rows, m, count_x, count_y;
m=0; count_x=0; count_y=0;

printf("Enter number of rows: n");
scanf("%d",&rows);

for(i=1; i<=rows; ++i)
{
for(space=1; space <= rows-i; ++space)
{
printf("  ");
++count_x;
}

while(m != 2*i-1)
{
if (count_x <= rows-1)
{
printf("%d ", i+m);
++count_x;
}
else
{
++count_y;
printf("%d ", (i+m-2*count_y));
}
++m;
}
count_y = count_x = m= 0;

printf("n");
}
return 0;
}

When the above code is executed it produced the following result

Pyramid triangle number Pattern in C Language using for loop
Example 4


Related Article

Pyramid Triangle in Java language
Floyd’s Triangle in Java language
Rectangle, Square in C++ language
Floyd,s Triangle in C++ language
Pyramid print in C++ language
Rectangle, Square in C language
Floyd,s Triangle in C language
Suggested for you
For loop in C language
while loop in C language
Do while loop in C language

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes