1. Star Pattern - 1
#include <stdio.h>
int main() {
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i) {
for (j = 1; j <= i; ++j) {
printf("* ");
}
printf("\n");
}
return 0;
}
Output :-
Enter the number of rows: 8
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
2. Star Pattern - 2
#include <stdio.h>
int main() {
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i) {
for (j = 1; j <= i; ++j) {
printf("* ");
}
printf("\n");
}
return 0;
}
Output :-
Enter the number of rows: 8
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
3. Star Pattern - 3
#include <stdio.h>
int main() {
int i, space, rows, k = 0;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i, k = 0) {
for (space = 1; space <= rows - i; ++space) {
printf(" ");
}
while (k != 2 * i - 1) {
printf("* ");
++k;
}
printf("\n");
}
return 0;
}
Output :-
Enter the number of rows: 8
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * *
4. Star Pattern - 4
#include <stdio.h>
int main() {
int rows, i, j, space;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i) {
for (space = 0; space < rows - i; ++space)
printf(" ");
for (j = i; j <= 2 * i - 1; ++j)
printf("* ");
for (j = 0; j < i - 1; ++j)
printf("* ");
printf("\n");
}
return 0;
}
Output :-
Enter the number of rows: 8
* * * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
5. Star Pattern - 5
#include <stdio.h>
int main()
{
int n;
printf("Enter the number of rows:");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
Output :-
Enter the number of rows: 8
********
********
********
********
********
********
********
********
6. Star Pattern - 6
#include <stdio.h>
int main(void) {
int n;
printf("Enter the number of columns:");
scanf("%d",&n);
//printing the upper part of the pattern..
for(int i=0;i<n;i++)
{
for(int j=0;j<i;j++)
{
printf(" ");
}
for(int k=1;k<=n-i;k++)
{
printf("*");
}
printf("\n");
}
for(int i=1;i<n;i++)
{
for(int j=1;j<n-i;j++)
{
printf(" ");
}
for(int k=1;k<=i+1;k++)
{
printf("*");
}
printf("\n");
}
return 0;
}
Output :-
Enter the number of columns: 8
********
*******
******
*****
****
***
**
*
**
***
****
*****
******
*******
********
7. Star Pattern - 7
#include <stdio.h>
int main(void) {
int n;
printf("Enter the number of columns:");
scanf("%d",&n);
//printing the upper part of the pattern..
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n-i;j++)
{
printf(" ");
}
for(int k=0;k<=n-i;k++)
{
printf("*");
}
printf("\n");
}
for(int i=1;i<n;i++)
{
for(int j=1;j<i+1;j++)
{
printf(" ");
}
for(int k=1;k<=i+1;k++)
{
printf("*");
}
printf("\n");
}
return 0;
}
Output :-
Enter the number of columns: 8
********
*******
******
*****
****
***
**
*
**
***
****
*****
******
*******
********
8. Star Pattern - 8
#include <stdio.h>
int main(void) {
int n;
printf("Enter the number of rows:");
scanf("%d",&n);
int spaces=n-1;
int stars=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=spaces;j++)
{
printf(" ");
}
for(int k=1;k<=stars;k++)
{
printf("*");
}
if(spaces>i)
{
spaces=spaces-1;
stars=stars+2;
}
if(spaces<i)
{
spaces=spaces+1;
stars=stars-2;
}
printf("\n");
}
return 0;}
Output :-
Enter the number of rows: 8
*
***
*****
*******
*******
*****
***
*
0 Comments