1. Star Pyramid Patterns
Program to print the half Pyramid
Let's explore an illustration demonstrating how to generate the half Pyramid pattern utilizing a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, rows;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = 1; i <= rows; ++i) // outer loop
{
for (j = 1; j <= i; ++j) // inner loop
{
printf ("* "); // print the Star
}
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print an inverted half Pyramid Pattern
Let's explore a sample scenario where we utilize a for loop to display an Inverted half Pyramid pattern.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, rows;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = rows; i > 0; i--) // define the outer loop
{
for (j = i; j > 0; j--) // define the inner loop
{
printf ("* "); // print the Star
}
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print an inverted right half Pyramid
Let's explore an illustration on how to display a right half Pyramid pattern in reverse using a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, rows, k;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= i; j++)
{
printf(" ");
}
for (k = i; k <= rows; k++)
{
printf("*"); // print the Star
}
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the right half Pyramid
Let's explore an illustration demonstrating how to display a right half Pyramid pattern by utilizing a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, rows, k;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = 1; i <= rows; i++)
{
for (j = i; j < rows; j++)
{
printf(" ");
}
for (k = 1; k <= i; k++)
{
printf("*"); // print the Star
}
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the full Pyramid of Star in 180 degree
Let's explore an illustration for displaying the complete Star Pyramid in 180-degree orientation by utilizing a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
int num, i, j, m = 1; // declare local variables
printf (" Enter the number to define the columns: \n");
scanf ("%d", & num);
for (i = 1; i <= num; i++)
{
for (j = 1; j <= i; j++)
{
printf( "* ");
}
printf("\n");
}
for (i = num-1; i >= 1; i--)
{
for (j = 1; j <= i; j++)
{
printf ("* ");
}
printf("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the full Pyramid of Star in the opposite direction
Let's explore a demonstration for printing a complete Star Pyramid in the reversed orientation of 180 degrees by employing a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows, k;
printf (" Enter a number to define the columns: \n ");
scanf("%d", &rows);
printf("\n");
for (i = 1; i <= rows; i++)
{
for (j = i; j < rows; j++)
{
printf(" ");
}
for (k = 1; k <= i; k++)
{
printf("*"); // print the Star
}
printf ("\n");
}
for (i = 1; i <= rows; ++i)
{
for (j = 2; j <= i; j++)
{
printf(" ");
}
for (k = i; k <= rows; k++)
{
printf("*"); // print the Star
}
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the full Pyramid of Star
Let's explore an illustration demonstrating how to display a complete Pyramid of Stars utilizing a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, rows, k = 0;
printf (" Enter a number to define the rows: \n");
scanf ("%d", &rows);
for ( i =1; i <= rows; i++)
{
for ( j = 1; j <= rows - i; j++)
{
printf (" ");
}
// use for loop where k is less than equal to (2 * i -1)
for ( k = 1; k <= ( 2 * i - 1); k++)
{
printf ("* "); // print the Star
}
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the inverted full Pyramid of Star
Let's explore an illustration demonstrating how to display a complete Pyramid of Asterisks using a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows, k, m = 1;
printf (" Enter a number to define the rows: \n");
scanf ("%d", &rows);
printf("\n");
for ( i = rows; i >= 1; i--)
{
for ( j = 1; j <= m; j++)
{
printf (" "); // print the space
}
for ( k = 1; k <= ( 2 * i - 1); k++)
{
printf ("* "); // print the Star
}
m++;
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the rhombus pattern of Star
Let's explore an illustration demonstrating how to utilize a for loop to display a rhombus pattern composed of asterisks.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows, k;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
int space = rows-1, num=1;
printf("\n");
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= space; j++)
{
printf(" "); / print the number
}
for ( k= 1; k <= num; k++)
{
printf(" *");
}
if(space > i)
{
space = space -1;
num = num+2;
}
if(space <i)
{
space = space + 1;
num = num -2;
}
printf("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
2. Number Pyramid Patterns
Program to print the half Pyramid of number
Let's examine a demonstration of how to display the half Pyramid design using a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = 1; i <= rows; ++i)
{
for (j = 1; j <= i; ++j)
{
printf ("%d ", j);
}
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Example 2:
Let's explore a sample scenario to display a half pyramid pattern of numbers utilizing a for loop.
Star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = 1; i <= rows; ++i)
{
for (j = 1; j <= i; ++j)
{
printf ("%d ", i); // print the number
}
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print an inverted half Pyramid Pattern
Let's explore an illustration demonstrating how to display the Inverted half Pyramid pattern using a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = rows; i > 0; i--) // define the outer loop
{
for (j = i; j > 0; j--) // define the inner loop
{
printf ("%d ", j);
}
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the right half Pyramid of number
Let's explore an illustration demonstrating how to generate a numeric right half pyramid pattern utilizing a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows, k;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = 1; i <= rows; i++)
{
for (j = i; j < rows; j++)
{
printf(" ");
}
for (k = 1; k <= i; k++)
{
printf(" %d", k);
}
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print an inverted right half Pyramid of number
Let's explore an illustration for displaying a right half Pyramid pattern of numbers in reverse order using a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows, k;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= i; j++)
{
printf(" ");
}
for (k = i; k <= rows; k++)
{
printf(" %d", k);
}
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the Floyd triangle
Let's explore an illustration demonstrating how to display the Floyd Pyramid pattern utilizing a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows, k = 1;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= i; j++)
{
printf("%d ", k);
k += 1;
}
printf("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the diamond shaped Pyramid of number
Let's explore an illustration demonstrating how to generate a diamond-shaped pyramid using a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows, k;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
int space = rows-1, num=1;
printf("\n");
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= space; j++)
{
printf(" ");
}
for ( k= 1; k <= num; k++)
{
printf("%d", k);
}
if(space > i)
{
space = space -1;
num = num+2;
}
if(space <i)
{
space = space + 1;
num = num -2;
}
printf("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the full Pyramid of number
Let's explore an illustration demonstrating the printing of a complete number Pyramid using a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows, k = 0;
printf (" Enter a number to define the rows: \n");
scanf ("%d", &rows); // take a number
for ( i =1; i <= rows; i++)
{
// inner loop define j should be less than equal to rows- i
for ( j = 1; j <= rows - i; j++)
{
printf (" "); // print the space
}
// use for loop where k is less than equal to (2 * i -1)
for ( k = 1; k <= ( 2 * i - 1); k++)
{
printf ("%d ",i); // print the number
}
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the inverted full Pyramid of number
Let's explore an illustration demonstrating how to utilize a for loop to display an inverted full pyramid of numbers.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows, k, m = 1;
printf (" Enter a number to define the rows: \n");
scanf ("%d", &rows); // take a number
printf("\n");
// outer loop define the total rows and i should be greater than equal to 1
for ( i = rows; i >= 1; i--)
{
// inner loop define j should be less than equal to m
for ( j = 1; j <= m; j++)
{
printf (" ");
}
for ( k = 1; k <= ( 2 * i - 1); k++)
{
printf ("%d ", i); // print the number
}
m++;
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the Pascal triangle
Let's explore a case study on generating the Pascal triangle using a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows, k, m;
printf (" Enter a number to define the rows: \n");
scanf ("%d", &rows);
printf("\n");
// outer loop define the total rows and i should be less than equal to rows
for ( i = 1; i <= rows; i++)
{
// inner loop define j should be less than equal to rows- i
for ( j = 1; j <= rows-i; j++)
{
printf (" ");
}
// use for loop where k is less than equal to i
for ( k = 1; k <= i; k++)
{
printf ("%d", k); // print the number
}
for (m = i-1; m >=1; m--)
{
printf("%d", m); // print the number
}
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to combine two half Pyramid of number
Let's explore an illustration showcasing how to display the combination of two half pyramids of numbers.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows, k;
printf (" Enter a number to define the rows: \n");
scanf ("%d", &rows); // take a number
printf("\n");
for ( i = 1; i <= rows; i++)
{
for ( j = 1; j <= rows; j++)
{
if( j <= i)
printf ("%d", j);
else
printf(" ");
}
for (j = rows; j >= 1; j--)
{
if(j <= i)
printf ("%d", j);
else
printf(" ");
}
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
3. Alphabets Pyramid Patterns
Program to print the half Pyramid of alphabets
Let's explore an illustration demonstrating how to display a half Pyramid pattern by utilizing a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = 1; i <= rows; ++i) // define the outer loop
{
for (j = 1; j <= i; ++j) // define the inner loop
{
printf ("%c ", 'A' + j - 1); // print the alphabets
}
printf ("\n"); // jump to next line
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the inverted half Pyramid of alphabets
Let's explore an illustration demonstrating how to display a half pyramid pattern using a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows, ch = 'A';
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = rows; i > 1; i--)
{
for (j = 1; j < i; j++)
{
printf ("%c ", ch);
}
ch++;
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the right half Pyramid of alphabets
Let's explore an illustration of generating a half Pyramid pattern utilizing a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows, k, ch='A';
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = 1; i <= rows; i++)
{
for (j = i; j < rows; j++)
{
printf(" ");
}
for (k = 1; k <= i; k++)
{
printf(" %c", ch);
}
ch++;
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the inverted half Pyramid of alphabets
Let's explore an instance of generating a half Pyramid pattern using a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, rows, k;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= i; j++)
{
printf(" ");
}
for (k = i; k <= rows; k++)
{
printf(" %c", 'A' + k);
}
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the full Pyramid of alphabets
Let's explore an instance to display the complete Pyramid pattern using a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, rows, k, ch = 'A';
printf (" Enter a number to define the rows: \n");
scanf ("%d", &rows);
for ( i =1; i <= rows; i++)
{
for ( j = 1; j <= rows - i; j++)
{
printf (" ");
}
// use for loop where k is less than equal to (2 * i -1)
for ( k = 1; k <= ( 2 * i - 1); k++)
{
printf ("%c ", ch);
}
ch++;
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the inverted full Pyramid of alphabets
Let's explore an illustration demonstrating how to display the complete Pyramid pattern using a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows, k, m = 1;
printf (" Enter a number to define the rows: \n");
scanf ("%d", &rows);
printf("\n");
for ( i = rows; i >= 1; i--)
{
for ( j = 1; j <= m; j++)
{
printf (" ");
}
// use for loop where k is less than equal to (2 * i -1)
for ( k = 1; k <= ( 2 * i - 1); k++)
{
printf ("%c ", 'A' + k - 1);
}
m++;
printf ("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the diamond shaped Pyramid of alphabets
Let's explore an illustration for displaying the complete Pyramid structure using a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
// declare the local variables
int i, j, rows, k;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
int space = rows-1, num=1;
printf("\n");
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= space; j++)
{
printf(" ");
}
for ( k= 1; k <= num; k++)
{
printf("%c", 'A' + k - 1);
}
if(space > i)
{
space = space -1;
num = num+2;
}
if(space <i)
{
space = space + 1;
num = num -2;
}
printf("\n");
}
getch();
}
Output
Enter a number to define the rows:
*
Program to print the full Pyramid of alphabets in 180 degrees
Let's explore an illustration demonstrating how to display the complete Pyramid design at a 180-degree angle by employing a for loop.
star.c
#include <stdio.h>
#include <conio.h>
void main()
{
int num, i, j, m = 1; // declare local variables
printf (" Enter the number to define the columns: \n");
scanf ("%d", & num);
for (i = 1; i <= num; i++)
{
for (j = 1; j <= i; j++)
{
printf( "%c", 'A' + j -1);
}
printf("\n");
}
for (i = num-1; i >= 1; i--)
{
for (j = 1; j <= i; j++)
{
printf ("%c", 'A' + j -1);
}
printf("\n");
}
getch();
}
Output