Question 1: Write the code that prints the square star pattern on the output screen.
Solution:
#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;
}
You can run this code:- Click here
Question 2: Write the code that prints the Hollow Square Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==1 ||i==n||j==1||j==n)
{
printf("*");
}
else
printf(" ");
}
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 3 : Write the code that prints the Hollow Square Pattern with Diagonal on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==1 ||i==n||j==1||j==n-i+1||i==j||j==n)
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 4: Write the code that prints the Rhombus Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=n;i>=1;i--)
{
for(int j=1;j<=i-1;j++)
{
printf(" ");
}
for(int k=1;k<=n;k++)
{
printf("*");
}
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 5: Write the code that prints the Hollow Rhombus Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=n;i>=1;i--)
{
for(int j=1;j<=i-1;j++)
{
printf(" ");
}
for(int k=1;k<=n;k++)
{
if(i==1 || i==n || k==1 || k==n)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 6: Write the code that prints the Mirrored Rhombus Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<i;j++)
{
printf(" ");
}
for(int k=1;k<=n;k++)
{
printf("*");
}
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 7: Write the code that prints the Hollow Mirrored Rhombus Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<i;j++)
{
printf(" ");
}
for(int k=1;k<=n;k++)
{
if(i==1 || i==n || k==1 || k==n)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 8: Write the code that prints the Right Triangle Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
printf("* ");
}
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 9: Write the code that prints the Hollow Right Triangle Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
if(j==1|| i==j || i==n )
{
printf("*");
}
else
printf(" ");
}
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 10: Write the code that prints the Mirrored Right Triangle Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n,m=1;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=n;i>=1;i--)
{
for(int j=1;j<=i-1;j++)
{
printf(" ");
}
for(int k=1;k<=m;k++)
{
printf("*");
}
printf("\n");
m++;
}
return 0;
}
You can run this code:- Click here
Question 11: Write the code that prints the Hollow Mirrored Right Triangle Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n,m=1;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=n;i>=1;i--)
{
for(int j=1;j<=i-1;j++)
{
printf(" ");
}
for(int k=1;k<=m;k++)
{
if(k==1 || k==m || m==n)
printf("*");
else
printf(" ");
}
printf("\n");
m++;
}
return 0;
}
You can run this code:- Click here
Question 12: Write the code that prints the Inverted Right Triangle Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n,m=1;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=n;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 13: Write the code that prints the Hollow Inverted Right Triangle Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n,m=1;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=n;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
if(j==1 || j==i || i==n)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 14: Write the code that prints the Inverted Mirrored Right Triangle Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n,m;
printf("Enter the number of rows");
scanf("%d",&n);
m=n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<i;j++)
{
printf(" ");
}
for(int k=1;k<=m;k++)
{
printf("*");
}
m--;
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 15: Write the code that prints the Hollow Inverted Mirrored Right Triangle Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n,m;
printf("Enter the number of rows");
scanf("%d",&n);
m=n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<i;j++)
{
printf(" ");
}
for(int k=1;k<=m;k++)
{
if(i==1 || k==1 || k==m)
printf("*");
else
printf(" ");
}
m--;
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 16: Write the code that prints the Pyramid Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n,m;
printf("Enter the number of rows");
scanf("%d",&n);
m=n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m-1;j++)
{
printf(" ");
}
for(int k=1;k<=2*i-1;k++)
{
printf("*");
}
m--;
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 17: Write the code that prints the Hollow Pyramid Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n,m;
printf("Enter the number of rows");
scanf("%d",&n);
m=n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m-1;j++)
{
printf(" ");
}
for(int k=1;k<=2*i-1;k++)
{
if(k==1 || k==2*i-1 || i==n)
printf("*");
else
printf(" ");
}
m--;
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 18: Write the code that prints the Inverted Pyramid Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n,m=1;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=n;i>=1;i--)
{
for(int j=1;j<m;j++)
{
printf(" ");
}
for(int k=1;k<=2*i-1;k++)
{
printf("*");
}
m++;
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 19: Write the code that prints the Hollow Pyramid Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n,m=1;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=n;i>=1;i--)
{
for(int j=1;j<m;j++)
{
printf(" ");
}
for(int k=1;k<=2*i-1;k++)
{
if(k==1 || k==2*i-1 || i==n)
printf("*");
else
printf(" ");
}
m++;
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 20: Write the code that prints the Inverted Pyramid Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n,m=1;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=n;i>=1;i--)
{
for(int j=1;j<m;j++)
{
printf(" ");
}
for(int k=1;k<=2*i-1;k++)
{
printf("*");
}
m++;
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 21: Write the code that prints the Inverted Hollow Pyramid Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n,m=1;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=n;i>=1;i--)
{
for(int j=1;j<m;j++)
{
printf(" ");
}
for(int k=1;k<=2*i-1;k++)
{
if(k==1 || k==2*i-1 || i==n)
printf("*");
else
printf(" ");
}
m++;
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 22: Write the code that prints the Half Diamond Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main()
{
int n,m=1;
printf("Enter the number of columns");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
for(int i=n-1;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 23: Write the code that prints the Diamond Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main(void) {
int n;
printf("Enter the number of rows\n");
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;
}
You can run this code:- Click here
Question 24: Write the code that prints the Right Arrow Star Pattern on the output screen.
Solution:
#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;
}
You can run this code:- Click here
Question 25: Write the code that prints the Left Arrow Star Pattern on the output screen.
Solution:
#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;
}
You can run this code:- Click here
Question 26: Write the code that prints the Plus Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main(void) {
int n;
printf("Enter the odd number only");
scanf("%d", &n);
for(int i=1;i<=n;i++)
{
if(i==((n/2)+1))
{
for(int j=1;j<=n;j++)
{
printf("+");
}
}
else
{
for(int j=1;j<=n/2;j++)
{
printf(" ");
}
printf("+");
}
printf("\n");
}
return 0;
}
You can run this code:- Click here
Question 27: Write the code that prints the X Star Pattern on the output screen.
Solution:
#include <stdio.h>
int main(void) {
int n,m;
printf("Enter the number");
scanf("%d",&n);
m=2*n-1;
for(int i=1;i<=m;i++)
{
for(int j=1;j<=m;j++)
{
if(i==j || j==(m-i+1))
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
return 0;
}
You can run this code:- Click here
0 Comments
If you are a good learner please leave a challenging question on comment box for us when you visited this website ( Coding with Fun).