Wednesday, October 7, 2020

C Square Star Pattern

 

CODE :-

#include <stdio.h>
int main()
{
int i, j, num;
printf("Enter a number: ");
scanf("%d",&num);
printf("\n");
for(i = 0; i < num; i++)
{
for(j = 0; j < num; j++)
{
printf("*");
}
printf("\n");
}
return 0;
}

C Inverted Pyramid Star Pattern

 

CODE :-

#include<stdio.h>
int main()
{
int i, j, k, m = 10;
for(i = 1;i <= 5;i++)
{
for(j = 1;j < i;j++)
{
printf(" ");
}
for(k = 1;k < m;k++)
{
printf("*");
}
m = m - 2;
printf("\n");
}
return 0;
}

C Mirrored Rhombus Star Pattern

 



CODE :-

#include<stdio.h>
int main()
{
int i, j, k, num, n;
printf("\nEnter a number: ");
scanf("%d",&num);
printf("\n");
n = num;
for(i = 0; i < num; i++)
{
for(k = 0; k < i+1; k++)
{
printf(" ");
}
for(j = 0; j < num; j++)
{
printf("*");
}
printf("\n");
}
return 0;
}

C Mirrored Hollow Rhombus Star Pattern

 

CODE :-

#include<stdio.h>
int main()
{
int i, j, k, num;
printf("\nEnter a number: ");
scanf("%d",&num);
printf("\n");
for(i = 0; i < num; i++)
{
for(k = 0; k < i+1; k++)
{
printf(" ");
}
for(j = 0; j < num; j++)
{
if(i == 0 || i == num - 1)
{
printf("*");
continue;
}
if(j == 0 || j == num - 1)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}


C Diamond Star Pattern

 

CODE :-

#include<stdio.h>
int main()
{
int i, j, k, m = 8;
for(i = 1;i <= 5;i++)
{
for(j = 5;j > i;j--)
{
printf(" ");
}
for(k = 1;k <= ((j*2)-1);k++)
{
printf("*");
}
printf("\n");
}
for(i = 1;i <= 4;i++)
{
for(j = 1;j <= i;j++)
{
printf(" ");
}
for(k = i;k < m;k++)
{
printf("*");
}
m-=1;
printf("\n");
}
return 0;
}

Tuesday, October 6, 2020

Hollow Diamond Square Star Pattern In C

 


CODE :-

#include<stdio.h>
int main()
{
int i, j, k, m, a = 1,b = 0;
for(i = 5;i > 0;i--)
{
for(j = i;j > 0;j--)
{
printf("*");
}
for(k = 1;k < a;k++)
{
printf(" ");
}
a = a + 2;
for(m = i;m > 0;m--)
{
printf("*");
}
printf("\n");
}
for(i = 1;i <= 4;i++)
{
for(j = 0;j <= i;j++)
{
printf("*");
}
for(k = 6;k > b;k--)
{
printf(" ");
}
b = b + 2;
for(m = 0;m <= i;m++)
{
printf("*");
}
printf("\n");
}
return 0;
}