Showing posts with label C pattern. Show all posts
Showing posts with label C pattern. Show all posts

Saturday, 25 August 2018

Program in C to print different types of pattern

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

Output screen :: 

Enter number of rows :: 5

output :: 

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

        

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 ::



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












Featured post

Kalgudi Interview Round!!

Those who cleared the second round of kalgudi got an email from exceller to complete their Kalgudi Interview Round. So here we will discuss ...