C programming code to display asterisk in X pattern

Share This Topic:

Course Details

Field of Study: Computer Science and Engineering
Course Name: C Programming
Course Description: C programming code to display asterisk in X pattern where the length of X is given by n

Code
#include<conio.h>
#include<stdio.h>
void main()
{
int n,i,j;
clrscr();
printf(“Enter the value of n”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
printf(“\n”);
for(j=1;j<=n;j++)
{
if((i==j)||(i+j==(n+1)))
printf(“*”);
else
printf(” “) ;
}
}
getch();
}

Output for n=7 is shown below
IMG_0298

Share this article:
Previous Post: C programming code to display asterisk in a right angle triangle

December 2, 2014 - In Academics, Computers

Next Post: C programming code to display asterisk in diagonal pattern

December 2, 2014 - In Academics, Computers

Related Posts

Leave a Reply

Your email address will not be published.