C programming code to display asterisk in diagonal 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 diagonal pattern where the length of the diagonal is given by n

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

Output for n=7 is shown below
IMG_0295

Share this article:
Previous Post: C programming code to display asterisk in X pattern

December 2, 2014 - In Academics, Computers

Next Post: C programming code to display asterisk in a rectangle pattern

December 2, 2014 - In Academics, Computers

Related Posts

Leave a Reply

Your email address will not be published.