For printing this type structure in C:
* * * * *
* * * * *
* * * *
* * *
* *
*
/* program to print structure */
#include<stdio.h>
void main()
{
int i,j,n ;
clrscr () ;
printf ("\n Enter number of rows:") ;
scanf ("%d", &n) ;
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
Here as we seen the figure is in row and column form thus we have to declare two variable ( i and j ) for row and column respectively. Here we use for loop statement of c.
/* program to print structure */
#include<stdio.h>
void main()
{
int i,j,n ;
clrscr () ;
printf ("\n Enter number of rows:") ;
scanf ("%d", &n) ;
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
if (i<=j)
printf ("*") ;
printf ("*") ;
else
printf (" ") ;
}
printf ("\n") ;
}
getch () ;
}
Output screen ::
Enter number of rows :: 5
output ::
}
printf ("\n") ;
}
getch () ;
}
Output screen ::
Enter number of rows :: 5
output ::
* * * * *
* * * *
* * *
* *
*
Great way for us to know to print C
ReplyDeleteGood article.informative
ReplyDeleteWell, this seems a very fun way to generate interest of kids in C and other coding languages. I remember hating those big big codes. These short and sweet codes would generate anyone's interest in coding.
ReplyDeleteAs a non techie, a little bit of introduction on what is this used for would be helpful. Or may be your article is for the programmers?
ReplyDeleteI'm totally lost. lol. I guess programming is not my thing.
ReplyDeleteI have no idea about coding or C language. But a lil intro never hurt anyone right?
ReplyDeleteWhat is this used for? I have no clue what it is.
ReplyDeleteHere we write C program to print pattern in C
DeleteThanks for taking the time to share. This stuff can be confusing.
ReplyDeleteI took a programming class in college and still find it so difficult to understand.
ReplyDeleteYou can learn here programming in very easy way.
DeleteWow! this is great idea from you. Nice one!
ReplyDeleteI have no idea what this means, but looks like you love what you do!
ReplyDeletegreat information... This is going to be very helpful for the students.
ReplyDeleteProgramming is not my thing. :( I'm happy to see that a lot of people learned from your blog.
ReplyDeleteThanks bro
DeleteI learnt C++ when I was in college...seems so long ago
ReplyDeleteLearn here C++ if you want
Deletewow sounds too complicating to understand. Maybe il have to learn everything from the scratch
ReplyDelete