0% found this document useful (0 votes)
123 views4 pages

C Programs for Number and Star Patterns

This document provides C programming examples for printing various patterns of numbers and stars using nested loops. It includes detailed code snippets for different patterns such as pyramids of stars and numerical sequences. The document aims to help users understand how to create their desired patterns by manipulating loops and character arrangements.

Uploaded by

indu priya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
123 views4 pages

C Programs for Number and Star Patterns

This document provides C programming examples for printing various patterns of numbers and stars using nested loops. It includes detailed code snippets for different patterns such as pyramids of stars and numerical sequences. The document aims to help users understand how to create their desired patterns by manipulating loops and character arrangements.

Uploaded by

indu priya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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