C Program to Print X Pattern

In this program we are going to make “X” number pattern and “X” star pattern. We make a C program to print x pattern using nested loop.

In this post, we are going to make a c program to print the “X” number pattern and also a c program to print the “X” star pattern. We will make a C program to print x pattern using a nested for loop.

C program to print x Number Pattern

#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:

C program to print x number pattern

C program to 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;
}

Output:
C program to print x star pattern

How to print a star pattern in c? [Video]

To make a C program to print x pattern, we are using nested for loop whose statements are written below. Please understand it carefully.
for(i=1;i<=7;i++) //It is outer loop
{
for(j=1;j<=7;j++) // It is inner loop
{
statement 1;
}
statement 2;


Define the nested loop?

A loop that contains another loop in its body. The inner loop must terminate before the outer loop.
The if-else format used in this program:-

if(condition)
statement 1;
else
statement 2;

Likewise:-

if((j==i)||(j==8-i))
printf("*");
else
printf(" ");



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 email 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.

Programs You may also like:-
C++ program to print star pattern
C program to print diamond star pattern.

Post a Comment

Please do not enter any spam link in the comment box.