In this post, we are going to make a c program to print the “X” number pattern and “X” star pattern. We will print x pattern using a nested for loop and simple if-else condition.
C program to print x Number Pattern
When “j” is at i th index from starting or i th index from ending then we have to print “i“, else we will print spaces.
#include <stdio.h>
int main()
{
int i, j;
for (i = 1; i <= 7; i++)
{
for (j = 1; j <= 7; j++)
{
if ((j == i) || (j == 8 - i))
printf("%d", i);
else
printf(" ");
}
printf("\n");
}
return 0;
}
Recommended Posts: Other Pattern Programs
Output:

Print x Star Pattern in C
#include <stdio.h>
int main()
{
int i, j;
for (i = 1; i <= 7; i++)
{
for (j = 1; j <= 7; j++)
{
if ((j == i) || (j == 8 - i))
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}

How to print a star pattern in c? [Video]
To make a program to print x pattern, we are using nested for loop whose statements are written below. Please understand it carefully. When variable “i” is 1 then “j” will run from to 7. Then “i” is incremented to 2, then inner loop will be executed.
for (i = 1; i <= 7; i++) // It is outer loop
{
for (j = 1; j <= 7; j++) // It is inner loop
{
statement 1;
}
statement 2;
A loop that contains another loop in its body. The inner loop must terminate before the outer loop.
About this blog post:
This Program is written by Vipul Khokhar. He is a very much talented guy in making different types of pattern programs.
Thanks for reading the C program to print the x pattern. I hope you enjoy these programs as much as I enjoy offering them to you. So, please share this program with your friends to support us. If you have any doubts related to this program please don’t hesitate to comment below or you can also contact us.
If you are interested in making pattern programs in c language, C++ language, then you should have to follow us by subscribing to our newsletter to get all the latest content delivered straight to your inbox. It is brought to you by the feed burner of google so don’t hesitate to follow us by email.