These program prints various different patterns of numbers and stars. These codes illustrate how to create various patterns using c programming. Most of these c programs involve usage of nested loops and space. A pattern of numbers, star or characters is a way of arranging these in some logical manner or they may form a sequence. Some of these patterns are triangles which have special importance in mathematics. Some patterns are symmetrical while other are not. Please see the complete page and look at comments for many different patterns.
Output:
Consider the pattern
*
**
***
****
*****
to print above pattern see the code below:
For more patterns or shapes on numbers and characters see comments below and also see codes on following pages:
Floyd triangle
Pascal triangle
* *** ***** ******* *********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 code
#include#include 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(); return 0; }
Output:
Consider the pattern
*
**
***
****
*****
to print above pattern see the code below:
#includemain() { 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"); } return 0; }
For more patterns or shapes on numbers and characters see comments below and also see codes on following pages:
Floyd triangle
Pascal triangle
star pattern source code
#include
main()
{
int n, c, k, space;
printf("Enter number of rows\n");
scanf("%d",&n);
space = n;
for ( k = 1 ; k <= n ; k++ )
{
for ( c = 1 ; c < space ; c++ )
printf(" ");
space--;
for( c = 1 ; c <= k ; c++ )
printf("*");
printf("\n");
}
return 0;
}
13/08/2011 - 17:29
#20 : number pattern source code
#include
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("%d", c);
printf("\n");
}
return 0;
}
12/08/2011 - 20:13
stars pattern using c programming
#include
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");
}
for ( c = n - 2 ; c >= 0 ; c-- )
{
for ( k = c ; k >= 0 ; k-- )
printf("*");
printf("\n");
}
return 0;
}
09/08/2011 - 22:38
code to print pattern of stars and numbers
#include
main()
{
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");
Comments
#1 Guest : i need code of this pattern
#2 adminPs : c program for character pattern
for this type:
01
010
1010
10101
c program to print pattern
can you write code for this
pr
pro
prog
progr
progra
program
: pattern for string
c programming code
1
121
12321
1234321
123454321
c program to print number pattern
c++ code to print pattern
c++ code to print pattern
may i get its source code
c code for number pattern
how to print this pattern
***S***
**SSS**
*SSSSS*
where S represents Space
#14 adminPs : c code for star pattern