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

Pattern Programs Flutter

The document contains multiple C programs that demonstrate various star pattern printing techniques, including right half pyramids, full pyramids, and inverted pyramids. Each program includes comments explaining the logic and structure of the loops used to generate the patterns. The examples are designed to help users understand how to manipulate loops and print characters in specific arrangements.

Uploaded by

Srizan
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)
44 views

Pattern Programs Flutter

The document contains multiple C programs that demonstrate various star pattern printing techniques, including right half pyramids, full pyramids, and inverted pyramids. Each program includes comments explaining the logic and structure of the loops used to generate the patterns. The examples are designed to help users understand how to manipulate loops and print characters in specific arrangements.

Uploaded by

Srizan
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
You are on page 1/ 10

Pattern Programs

1)

Enter Number: 5
*
**
***
****
*****

#include <stdio.h>

int main()
{
int i,j,n;

printf("Enter Number: ");


scanf("%d",&n);

for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf("* ");
//printf("%d ", j +1);
//printf("%c ", 'A' + j);
}
printf("\n");
}
return 0;
}

==================================================
=====

2)
// c program to print left half pyramid pattern of star
#include <stdio.h>

int main()
{
int rows = 5;

// first loop is for printing the rows


for (int i = 0; i < rows; i++)
{

// loop for printing leading whitespaces


for (int j = 0; j < 2 * (rows - i) - 1; j++)
//for (int j = 0; j < 2 * (rows - i) - 2; j++)
//for (int j = 0; j < 2 * (rows - i) - 1; j++)
{
printf(" ");
}
// loop for printing * character
for (int k = 0; k <= i; k++)
{
printf("* ");
//printf("%d ", k + 1);
//printf("%c ", 'A' + k);
}
printf("\n");
}
return 0;
}

==================================================
=====

3)

// C program to print the full pyramid pattern of stars


#include <stdio.h>
int main()
{
int rows = 5;

// first loop to print all rows


for (int i = 0; i < rows; i++)
{

// inner loop 1 to print white spaces


for (int j = 0; j < 2 * (rows - i) - 1; j++)
{
printf(" ");
}

// inner loop 2 to print star * character


for (int k = 0; k < 2 * i + 1; k++)
{
printf("* ");
// printf("%d ", k + 1);
// printf("%c ", 'A' + k);
}
printf("\n");
}
return 0;
}

==================================================
=====
4)

// C program to print the inverted right half pyramid of

#include <stdio.h>

int main()
{
int rows = 5;

// first loop to print all rows


for (int i = 0; i < rows; i++)
{

// first inner loop to print the * in each row


for (int j = 0; j < rows - i; j++)
{
printf("* ");
// printf("%d ", j + 1);
// printf("%c ", 'A' + j);
}
printf("\n");
}
}

==================================================
=====

5)

// C program to print the inverted right half pyramid of


// stars
#include <stdio.h>

int main()
{
int rows = 5;

// first loop to print all rows


for (int i = 0; i < rows; i++)
{
// first inner loop to print the * in each row
for (int j = 0; j < rows - i; j++)
{
printf("* ");
// printf("%d ", j + 1);
// printf("%c ", 'A' + j);
}
printf("\n");
}
}

==================================================
=====

6)

// Online C compiler to run C program online


#include <stdio.h>
int main()
{

int n=7,i,j;

for (i = 1 ; i <= n ; i++)


{
for(j=1;j<=n;j++)
{
if(i==1|| i==n || j==1 || j==n || i==j || i+j==n+1 )
printf("* ");
else
printf(" ");
}
printf("\n");
}

return 0;
}

==================================================
=====

7)

==================================================
=====

You might also like