Select Page

How to make “X” type pattern using the symbol – In this tutorial, we will cover techniques to printing a modified “X” Pattern using star or any other symbol in the C programming language.

The following Pattern program is written in three unique manners:

• For Loop
•  While Loop
•  Do-While Loop

Enter Size: 7 According to the above Pattern number of rows specified 7 and the number of Columns specified also 7.

The “at the rate of” Symbol(any other symbol can take) is picked to do the distinctions according to the name of the title itself.

This issue can also be solved by observing that the symbol is printed along the left and right diagonals only if we enclose the pattern within a matrix. Now this pattern can be enclosed within a square matrix of order size.

## 1. “X” Type Pattern using For Loop

### Algorithm of above Pattern

Input: Let, three variables say r,c,s. The value of n will be given by the user.

step 1: Input values for s

step 2: r=1 and outer loop will be performed as long as r<=s

step 3: c=1

step 4: inner loop will be performed as long as  c<=s

step 4.1: check if (c==r||c==(s+1-r)) is true then

print symbol star ( “@”)

else

print  “blank space”

step 5: j=j+1

step 6: End inner loop

step 7: next line start

step 8: i= i+1

step 9:  End outer loop

### Source Code

```int main()
{
int r,c,s;
printf("\n\tEnter Size:");
scanf("%d",&s);
printf("\n\t");
for(r=1; r<=s; r++)
{
for(c=1; c<=s; c++)
{
if(c==r||c==(s+1-r))
{
printf("@");
}
else
{
printf(" ");
}
}
printf("\n");
printf("\t");
}
return 0;
}

```

## “X” Type Pattern using while Loop

```int main()
{
int r,c,s;
printf("ntEnter no:");
scanf("%d",&s);
printf("\t");
r=1;
while(r<=s)
{
c=1;
while(c<=s)
{
if(c==r||c==(s+1-r))
{
printf("@");
}
else
{
printf(" ");
}
c++;
}
r++;
printf("\n");
printf("\t");
}
}
``` ## “X” Type Pattern using do..while Loop

```int main()
{
int r,c,s;
printf("ntEnter no:");
scanf("%d",&s);
printf("\t");
r=1;
do
{
c=1;
do
{
if(c==r||c==(s+1-r))
{
printf("@");
}
else
{
printf(" ");
}
c++;
}while(c<=s);

r++;
printf("\n");
printf("\t");
} while(r<=s);
}

``` 