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

C Pattern Programs

The document provides examples of various nested for loop pattern programs in C, including a right triangle, inverted triangle, pyramid, Floyd's triangle, same number pattern, and 0-1 pattern. Each pattern is accompanied by its output and corresponding C code. These examples demonstrate how to use nested loops to create different visual patterns in console output.

Uploaded by

temuar2
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)
3 views4 pages

C Pattern Programs

The document provides examples of various nested for loop pattern programs in C, including a right triangle, inverted triangle, pyramid, Floyd's triangle, same number pattern, and 0-1 pattern. Each pattern is accompanied by its output and corresponding C code. These examples demonstrate how to use nested loops to create different visual patterns in console output.

Uploaded by

temuar2
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

Nested For Loop Pattern Programs

Right Triangle Pattern


Output:​
*​
**​
***​
****​
*****

Code:​
#include <stdio.h>​
void main()​
{​
int i, j;​
for(i = 1; i <= 5; i++)​
{​
for(j = 1; j <= i; j++)​
{​
printf("*");​
}​
printf("\n");​
}​
}

Inverted Triangle
Output:​
*****​
****​
***​
**​
*

Code:​
#include <stdio.h>​
void main()​
{​
int i, j;​
for(i = 5; i >= 1; i--)​
{​
for(j = 1; j <= i; j++)​
{​
printf("*");​
}​
printf("\n");​
}​
}

Pyramid Pattern
Output:​
*​
***​
*****​
*******​
*********

Code:​
#include <stdio.h>​
void main()​
{​
int i, j;​
for(i = 1; i <= 5; i++)​
{​
for(j = 1; j <= 5 - i; j++)​
printf(" ");​
for(j = 1; j <= (2*i - 1); j++)​
printf("*");​
printf("\n");​
}​
}

Floyd’s Triangle
Output:​
1​
2 3​
4 5 6​
7 8 9 10

Code:​
#include <stdio.h>​
void main()​
{​
int i, j, num = 1;​
for(i = 1; i <= 4; i++)​
{​
for(j = 1; j <= i; j++)​
{​
printf("%d ", num++);​
}​
printf("\n");​
}​
}

Same Number Pattern


Output:​
1​
2 2​
3 3 3​
4444

Code:​
#include <stdio.h>​
void main()​
{​
int i, j;​
for(i = 1; i <= 4; i++)​
{​
for(j = 1; j <= i; j++)​
printf("%d ", i);​
printf("\n");​
}​
}

0-1 Pattern
Output:​
1​
0 1​
1 0 1​
0101

Code:​
#include <stdio.h>​
void main()​
{​
int i, j;​
for(i = 1; i <= 4; i++)​
{​
for(j = 1; j <= i; j++)​
{​
if((i+j)%2==0)​
printf("1 ");​
else​
printf("0 ");​
}​
printf("\n");​
}​
}

You might also like