C codes to print patterns of numbers stars and sambls
* ** *** **** *****
We have shown five rows above, in the program you will be asked to enter the numbers of rows you want to print in the pyramid of stars.
C programming code
Pattern numbers stars smables
Programming codes for the above patterns is given below ande you can change it according to your desire.
#include <stdio.h>
#include <conio.h>
int main()
{
int n, c, k;
printf("Enter number of rows\n");
scanf("%d",&n);
for ( c = 1 ; c <= n ; c++ )
{
for( k = 1 ; k <= c ; k++ )
printf("*");
printf("\n");
}
getch();
}
Example No 2
The following pattern is given below and we have to write its code and program will asks you how much rows of pattern you want to print
*
***
*****
*******
*********
Because there are 5 rows of above program so we will give 5 rows to program. The code of pattern is given below
#include <stdio.h>
#include <coni0.h>
void main()
{
int row, c, n, temp;
printf("Enter the number of rows in pyramid of stars you wish to see ");
scanf("%d",&n);
temp = n;
for ( row = 1 ; row <= n ; row++ )
{
for ( c = 1 ; c < temp ; c++ )
printf(" ");
temp--;
for ( c = 1 ; c <= 2*row - 1 ; c++ )
printf("*");
printf("\n");
}
getch();
}
Output of above code is
Using these examples you are in a better position to create your desired pattern for yourself. Creating a pattern involves how to use nested loops properly, some pattern may involve alphabets or other special characters. Key aspect is knowing how the characters in pattern changes.
C pattern programs example 3
Pattern:
# #A# #A#A# #A#A#A#
C pattern program of hash and A:
#include<stdio.h>
#include<stdio.h>
void main()
{
clrscr();
int n, c, k, space, count = 1;
printf("Enter number of rows\n");
scanf("%d",&n);
space = n;
for ( c = 1 ; c <= n ; c++)
{
for( k = 1 ; k < space ; k++)
printf(" ");
for ( k = 1 ; k <= c ; k++)
{
printf("#");
if ( c > 1 && count < c)
{
printf("A");
count++;
}
}
printf("\n");
space--;
count = 1;
}
getch();
}
Pattern:
1
232
34543
4567654
567898765
C program:
#include<stdio.h>
#include<stdio.h>
void main()
{
int n, c, d, num = 1, space;
scanf("%d",&n);
space = n - 1;
for ( d = 1 ; d <= n ; d++ )
{
num = d;
for ( c = 1 ; c <= space ; c++ )
printf(" ");
space--;
for ( c = 1 ; c <= d ; c++ )
{
printf("%d", num);
num++;
}
num--;
num--;
for ( c = 1 ; c < d ; c++)
{
printf("%d", num);
num--;
}
printf("\n");
}
getch();
}
I hope you will like these examples of patterns if you dont understand these examples clearly visits my vedios lactures with full explanations on you tube. ch-anal name is gillani data