Tuesday, 21 August 2018

Program in C to print different types of structure

For printing this type structure in C:

* * * * * 
* * * * * 
* * * * * 
* * * * * 
* * * * * 

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++)
{
printf ("*") ;
printf ("  ") ;
}
printf ("\n") ;
}
getch () ;
}

Output screen :: 

Enter number of rows :: 5

output :: 
            
* * * * * 
* * * * * 
* * * * * 
* * * * * 
* * * * * 

For printing this type structure in C:


* *
* * *
* * * *
* * * * *
* * * * * *


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<=i;j++)
{
printf ("*") ;
printf ("  ") ;
}
printf ("\n") ;
}
getch () ;
}

Both of program have nearly same syntax but there is small change in their column for loop statement in case of first type their condition is for (j=1;j<=n;j++) and in case second we have use for (j=1;j<=i;j++).

Output Screen :: 

Enter number of rows :: 5

output ::



* *
* * *
* * * *
* * * * *












3 comments:

  1. Thanks for sharing it! Due to limited time and a lot of work to do, I’m as a student often face difficulties and problems in terms of using and applying the C programming language. Luckily, I’ve found this service https://www.assignmentexpert.com/programming that helps me a lot. Experts provide me with practical and theoretical description of the c programming language. What I like is that they are accessible 24/7. So, even when I forget about my assignments and recall about them the night before I need to pass them, I can rely on their help. Highly recommend!

    ReplyDelete

Featured post

Program to find Volume of given box in java

class volume { public static void main (String args []) { int l=5,b=6,h=10; int volume; volume=l*b*h; System.out.println (" vol...