0% found this document useful (0 votes)
25 views

Pattern C Program

To create patterns in C programming, at least two loops are needed - an outer loop to iterate through rows and an inner loop to iterate through columns. The basic structure uses for loops with initialization, condition, and increment/decrement variables to control the rows and columns. Simple patterns like squares and triangles can be produced by varying the loop conditions and print statements, with the core structure staying the same.

Uploaded by

raj akbari
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Pattern C Program

To create patterns in C programming, at least two loops are needed - an outer loop to iterate through rows and an inner loop to iterate through columns. The basic structure uses for loops with initialization, condition, and increment/decrement variables to control the rows and columns. Simple patterns like squares and triangles can be produced by varying the loop conditions and print statements, with the core structure staying the same.

Uploaded by

raj akbari
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Pattern programs in c

•We have to use at least two loops to


make any pattern.
•First loop for number of row &
second loop for number of column.
Basic structure for pattern:

#include<stdio.h>
Void main()
{
Int I,j,n; \\(where I for rows & j for column)
for (intiolaization;condition;increement/decreement) \\(loop for rows)
{
for(intiolaization ; condition;increement/decreement)\\
(loop for colmun)
{
printf(“”);
}
}
}
Square programe
#include<stdio.h>
Void main()
{
Int I,j,n; \\(where I for rows & j for column)
for (i=1;i<=n;i++) \\(loop for rows)
{
for(j=1;j<=n;j++)\\ (loop for colmun)
{
printf(“*”);
}
}
}
output
• Assume value of n=5
*****
*****
*****
*****
*****
triangle
• We can make new patterns by just doing smaller changes
#include<stdio.h>
Void main()
{
Int I,j,n; \\(where I for rows & j for column)
for (i=1;i<=n;i++) \\(loop for rows)
{
for(j=1;j<=i;j++)\\ (loop for colmun)
{
printf(“*”);
}
}
}
Out put
• Assume value of n is 7
*
**
***
****
*****
******
*******
• We can print alphabets by just changing in
printf function.
• printf(“%c”,m);
• We can use numbers by using %d in printf
function

You might also like