You are on page 1of 4

2/28/2016 Cprogramtoprintpatternsofnumbersandstars|ProgrammingSimplified

Search

HomeCprogrammingCprogrammingexamplesCprogramtoprintpatternsofnumbersandstars

Cprogramtoprintpatternsofnumbersandstars
Theseprogramprintsvariousdifferentpatternsofnumbersandstars.Thesecodesillustrate
howtocreatevariouspatternsusingcprogramming.Mostofthesecprogramsinvolve
usageofnestedloopsandspace.Apatternofnumbers,starorcharactersisawayof
arrangingtheseinsomelogicalmannerortheymayformasequence.Someofthese
patternsaretriangleswhichhavespecialimportanceinmathematics.Somepatternsare
symmetricalwhileotherarenot.Pleaseseethecompletepageandlookatcommentsfor
manydifferentpatterns.

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

Wehaveshownfiverowsabove,intheprogramyouwillbeaskedtoenterthenumbersof
rowsyouwanttoprintinthepyramidofstars.

Cprogrammingcode
#include<stdio.h>

intmain()
{
introw,c,n,temp;

printf("Enterthenumberofrowsinpyramidofstarsyouwishtosee");
scanf("%d",&n);

temp=n;

for(row=1;row<=n;row++)
{
for(c=1;c<temp;c++)
printf("");

temp;

http://www.programmingsimplified.com/cprogramprintstarspyramid 1/4
2/28/2016 Cprogramtoprintpatternsofnumbersandstars|ProgrammingSimplified
for(c=1;c<=2*row1;c++)
printf("*");

printf("\n");
}

return0;
}

DownloadStarspyramidprogram.

Outputofprogram:

Formorepatternsorshapesonnumbersandcharactersseecommentsbelowandalsosee
codesonfollowingpages:
Floydtriangle
Pascaltriangle

Considerthepattern
*
**
***
****
*****

toprintabovepatternseethecodebelow:

#include<stdio.h>

intmain()
{
intn,c,k;

printf("Enternumberofrows\n");
scanf("%d",&n);

for(c=1;c<=n;c++)
{
for(k=1;k<=c;k++)
printf("*");

printf("\n");
}
http://www.programmingsimplified.com/cprogramprintstarspyramid 2/4
2/28/2016 Cprogramtoprintpatternsofnumbersandstars|ProgrammingSimplified

return0;
}

Usingtheseexamplesyouareinabetterpositiontocreateyourdesiredpatternforyourself.
Creatingapatterninvolveshowtousenestedloopsproperly,somepatternmayinvolve
alphabetsorotherspecialcharacters.Keyaspectisknowinghowthecharactersinpattern
changes.

Cpatternprograms
Pattern:


*
*A*
*A*A*
*A*A*A*

Cpatternprogramofstarsandalphabets:

#include<stdio.h>

main()
{
intn,c,k,space,count=1;

printf("Enternumberofrows\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;
}
return0;
}

Pattern:
http://www.programmingsimplified.com/cprogramprintstarspyramid 3/4
2/28/2016 Cprogramtoprintpatternsofnumbersandstars|ProgrammingSimplified

1
232
34543
4567654
567898765

Cprogram:

#include<stdio.h>

main()
{
intn,c,d,num=1,space;

scanf("%d",&n);

space=n1;

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");

}

return0;
}

http://www.programmingsimplified.com/cprogramprintstarspyramid 4/4

You might also like