Showing posts with label Pattern. Show all posts
Showing posts with label Pattern. Show all posts

Wednesday, March 9, 2016

Print pattern in c - star pattern-5

print star pattern in C language

Print pattern in c - star pattern


Write a program to print following pattern

   * 
  ** 
 *** 
****

Program code

#include<stdio.h>
int main()
{
    int rows,i,j,space;
    printf("Enter number of rows: ");
    scanf("%d",&rows);
    for(i=rows;i>=1;--i)
    {
        for(space=0;space<rows-i;++space)
           printf("  ");
        for(j=i;j<=2*i-1;++j)
          printf("* ");
        for(j=0;j<i-1;++j)
            printf("* ");
        printf("\n");
    }
    return 0;
}

You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Monday, March 7, 2016

Print pattern in c - number pattern-11

Print pattern in c - number pattern


Write a program to print following pattern

55555
4444
333
22
1

Program code

#include <stdio.h>



int main()

{

    int i, j;

    for(i=5;i>=1;i--)

    {

        for(j=1;j<=i;j++)

        {

            printf("%d",i);

        }

        printf("\n");

    }



    return 0;

}

You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Print pattern in c - star pattern-4

Print pattern in c - star pattern


Write a program to print following pattern

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

Program code

#include<stdio.h>
int main()
{
    int rows,i,j,space;
    printf("Enter number of rows: ");
    scanf("%d",&rows);
    for(i=rows;i>=1;--i)
    {
        for(space=0;space<rows-i;++space)
           printf("  ");
        for(j=i;j<=2*i-1;++j)
          printf("* ");
        for(j=0;j<i-1;++j)
            printf("* ");
        printf("\n");
    }
    return 0;
}

You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Print pattern in c - star pattern-3

Print pattern in c - star pattern


Write a program to print following pattern

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

Program code

#include <stdio.h>
int main()
{
    int i,space,rows,k=0;
    printf("Enter the number of rows: ");
    scanf("%d",&rows);
    for(i=1;i<=rows;++i)
    {
        for(space=1;space<=rows-i;++space)
        {
           printf("  ");
        }
        while(k!=2*i-1)
        {
           printf("* ");
           ++k;
        }
        k=0;
        printf("\n");
    }
    return 0;
}

You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Print pattern in c - star pattern-2

Print pattern in c - star pattern


Write a program to print following pattern

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

Program code

#include <stdio.h>
int main()
{
    int i,j,rows;
    printf("Enter the number of rows: ");
    scanf("%d",&rows);
    for(i=rows;i>=1;--i)
    {
        for(j=1;j<=i;++j)
        {
           printf("* ");
        }
    printf("\n");
    }
    return 0;
}



You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Print pattern in c - star pattern-1

Print pattern in c - star pattern


Write a program to print following pattern

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

Program code

#include <stdio.h>
int main()
{
    int i,j,rows;
    printf("Enter the number of rows: ");
    scanf("%d",&rows);
    for(i=1;i<=rows;++i)
    {
        for(j=1;j<=i;++j)
        {
           printf("* ");
        }
        printf("\n");
    }
    return 0;
}


You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Print pattern in c - number pattern -10

number-pattern

Print pattern in c - number pattern


Write a program to print following pattern

5
44
333
2222
11111

Program code

#include <stdio.h>

int main()
{
    int i, j;
    for(i=5;i>=1;i--)
    {
        for(j=5;j>=i;j--)
        {
            printf("%d",i);
        }
        printf("\n");
    }

    return 0;
} 

Step by Step solution

1. Number of row -

   Is has 5row  , so first loop will execute for 5 time
#include <stdio.h>
int main()

{

    int i, j;

    for(i=5;i>=1;i--)
    
{......
 }



    return 0;

}


2. Number of character -

 It has only one type of character , so there will be only one nested loop
#include <stdio.h>
int main()

{

......
 for(j=5;j>=i;j--)
        {
            printf("%d",i);
        }
        printf("\n");

}


3.Number of column -

It has 5 maximum column and is decreasing with row number , so the nested loop decrease it's repetation with increase in row
#include <stdio.h>

............
      for(j=5;j>=i;j--)
        {
            printf("%d",i);
        }
        printf("\n");
...................


    return 0;

}


You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Print pattern in c - number pattern -9

number-pattern

Print pattern in c - number pattern


Write a program to print following pattern

1
22
333
4444
55555

Program code

#include <stdio.h>

int main()
{
    int i, j;
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=i;j++)
        {
            printf("%d",i);
        }
        printf("\n");
    }

    return 0;
} 



Step by Step solution

1. Number of row -

   Is has 5row  , so first loop will execute for 5 time
#include <stdio.h>
int main()

{

    int i, j;

    for(i=1;i<=5;i++)
    
{......
 }



    return 0;

}


2. Number of character -

 It has only one type of character , so there will be only one nested loop
#include <stdio.h>
int main()

{

......
 for(j=1;j<=i;j++)
        {
            printf("%d",i);
        }
        printf("\n");

}


3.Number of column -

It has 5 maximum column and is decreasing with row number , so the nested loop decrease it's repetation with increase in row
#include <stdio.h>

............
      for(j=1;j<=i;j++)
        {
            printf("%d",i);
        }
        printf("\n");
...................


    return 0;

}


You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Print pattern in c - number pattern -8

number-pattern

Print pattern in c - number pattern


Write a program to print following pattern

5
54
543
5432
54321

Program code

#include <stdio.h>

int main()
{
    int i, j;
    for(i=5;i>=1;i--)
    {
        for(j=5;j>=i;j--)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}




Step by Step solution

1. Number of row -

   Is has 5row  , so first loop will execute for 5 time
#include <stdio.h>
int main()

{

    int i, j;

    for(i=5;i>=1;i--)
    
{......
 }



    return 0;

}


2. Number of character -

 It has only one type of character , so there will be only one nested loop
#include <stdio.h>
int main()

{

......
 for(j=5;j>=i;j--)
        {
            printf("%d",j);
        }
        printf("\n");

}


3.Number of column -

It has 5 maximum column and is decreasing with row number , so the nested loop decrease it's repetation with increase in row
#include <stdio.h>

............
      for(j=5;j>=i;j--)
        {
            printf("%d",j);
        }
        printf("\n");
...................


    return 0;

}


You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Print pattern in c - number pattern-7

number-pattern

Print pattern in c - number pattern


Write a program to print following pattern

1
21
321
4321
54321

Program code


#include <stdio.h>

int main()
{
    int i, j;
    for(i=1;i<=5;i++)
    {
        for(j=i;j>=1;j--)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}



Step by Step solution

1. Number of row -

   Is has 5row  , so first loop will execute for 5 time
#include <stdio.h>
int main()

{

    int i, j;

    for(i=1;i<=5;i++)
    
{......
 }



    return 0;

}


2. Number of character -

 It has only one type of character , so there will be only one nested loop
#include <stdio.h>
int main()

{

......
 for(j=i;j>=1;j--)
        {
            printf("%d",j);
        }
        printf("\n");
}


3.Number of column -

It has 5 maximum column and is decreasing with row number , so the nested loop decrease it's repetation with increase in row
#include <stdio.h>

............
      for(j=i;j>=1;j--)
        {
            printf("%d",j);
        }
        printf("\n");
...................


    return 0;

}


You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Print pattern in c - number pattern -6

number-pattern

Print pattern in c - number pattern -6


Write a program to print following pattern

5
45
345
2345
12345

Program code

#include <stdio.h>

int main()
{
    int i, j;
    for(i=5;i>=1;i--)
    {
        for(j=i;j<=5;j++)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}

Step by Step solution

1. Number of row -

   Is has 5row  , so first loop will execute for 5 time
#include <stdio.h>
int main()

{

    int i, j;

    for(i=5;i>=1;i--)
    
{......
 }



    return 0;

}


2. Number of character -

 It has only one type of character , so there will be only one nested loop
#include <stdio.h>
int main()

{

......
 for(j=i;j<=5;j++)
        {
            printf("%d",j);
        }
        printf("\n");

}


3.Number of column -

It has 5 maximum column and is decreasing with row number , so the nested loop decrease it's repetation with increase in row
#include <stdio.h>

............
     for(j=i;j<=5;j++)
        {
            printf("%d",j);
        }
        printf("\n");
...................


    return 0;

}


You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Print pattern in c - number pattern -5

number-pattern

Print pattern in c - number pattern -5


Write a program to print following pattern

1
12
123
1234
12345

Program code

#include <stdio.h>

int main()
{
    int i, j;
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=i;j++)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}



Step by Step solution

1. Number of row -

   Is has 5row  , so first loop will execute for 5 time
#include <stdio.h>
int main()

{

    int i, j;

    for(i=1;i<=5;i++)
    
{......
 }



    return 0;

}


2. Number of character -

 It has only one type of character , so there will be only one nested loop
#include <stdio.h>
int main()

{

......
  for(j=1;j<=i;j++)
        {
            printf("%d",j);
        }
        printf("\n");
}


3.Number of column -

It has 5 maximum column and is decreasing with row number , so the nested loop decrease it's repetation with increase in row
#include <stdio.h>

............
      for(j=1;j<=i;j++)
        {
            printf("%d",j);
        }
        printf("\n");
...................


    return 0;

}


You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Print pattern in c - number pattern -4

number-pattern-4

Print pattern in c - number pattern -4


Write a program to print following pattern

54321
5432
543
54
5

Program code

#include <stdio.h>

int main()
{
    int i, j;
    for(i=1;i<=5;i++)
    {
        for(j=5;j>=i;j--)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}


Step by Step solution

1. Number of row -

   Is has 5row  , so first loop will execute for 5 time
#include <stdio.h>
int main()

{

    int i, j;

    for(i=1;i<=5;i++)

    
{......
 }



    return 0;

}


2. Number of character -

 It has only one type of character , so there will be only one nested loop
#include <stdio.h>
int main()

{

......
 
        for(j=5;j>=i;j--)
        {
            printf("%d",j);
        }
        printf("\n");
 return 0;

}


3.Number of column -

It has 6 maximum column and is decreasing with row number , so the nested loop decrease it's repetation with increase in row
#include <stdio.h>

............
      
        for(j=5;j>=i;j--)
        {
            printf("%d",j);
        }
        printf("\n");
...................


    return 0;

}


You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Print pattern in c - number pattern -3

number-pattern

Print pattern in c - number pattern -3


Write a program to print following pattern

54321
4321
321
21
1

Program code

#include <stdio.h>

int main()
{
    int i, j;
    for(i=5;i>=1;i--)
    {
        for(j=i;j>=1;j--)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}



Step by Step solution

1. Number of row -

   Is has 5row  , so first loop will execute for 5 time
#include <stdio.h>
int main()

{

    int i, j;

    for(i=5;i>=1;i--)
    
{......
 }



    return 0;

}


2. Number of character -

 It has only one type of character , so there will be only one nested loop
#include <stdio.h>
int main()

{

......
 for(j=i;j>=1;j--)
        {
            printf("%d",j);
        }
        printf("\n");

}


3.Number of column -

It has 5 maximum column and is decreasing with row number , so the nested loop decrease it's repetation with increase in row
#include <stdio.h>

............
      for(j=i;j>=1;j--)
        {
            printf("%d",j);
        }
        printf("\n");
...................


    return 0;

}


You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Print pattern in c - number pattern -2

Print pattern in c - number pattern -2


Write a program to print following pattern

12345
2345
345
45
5

Program code

#include <stdio.h>



int main()

{

    int i, j;

    for(i=1;i<=5;i++)

    {

        for(j=i;j<=5;j++)

        {

            printf("%d",j);

        }

        printf("\n");

    }



    return 0;

}


Step by Step solution

1. Number of row -

   Is has 5row  , so first loop will execute for 5 time
#include <stdio.h>
int main()

{

    int i, j;

    for(i=1;i>=5;i++)

    
{......
 }



    return 0;

}


2. Number of character -

 It has only one type of character , so there will be only one nested loop
#include <stdio.h>
int main()

{

......
 for(j=i;j<=5;j++)

        {

            printf("%d",j);

        }

        printf("\n");

 return 0;

}


3.Number of column -

It has 6 maximum column and is decreasing with row number , so the nested loop decrease it's repetation with increase in row
#include <stdio.h>

............
        for(j=i;j<=5;j++)

        {

            printf("%d",j);

        }

        printf("\n");
...................


    return 0;

}


You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Sunday, March 6, 2016

print pattern in c - number pattern -1

Print pattern in c - number pattern -1


Write a program to print following pattern

123456
12345
1234
123
12
1

Program code

#include <stdio.h>
int main()
{

    int i, j;
    for(i=6;i>=1;i--)
     {

        for(j=1;j<=i;j++)

        {

            printf("%d",j);

        }

        printf("\n");

    }



    return 0;

}


Step by Step solution

1. Number of row -

   Is has 6 row  , so first loop will execute for 6 time
#include <stdio.h>
int main()

{

    int i, j;

    for(i=6;i>=1;i--)

    
{......
 }



    return 0;

}


2. Number of character -

 It has only one type of character , so there will be only one nested loop
#include <stdio.h>
int main()

{

......
 for(j=1;j<=i;j++)

        {

            printf("%d",j);

        }

 return 0;

}


3.Number of column -

It has 6 maximum column and is decreasing with row number , so the nested loop decrease it's repetation with increase in row
#include <stdio.h>

............
        for(j=1;j<=i;j++)

        {

            printf("%d",j);

        }
...................


    return 0;

}


You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Saturday, February 27, 2016

Print pattern in c - explore new perspectives in pattern printing

pattern in c

Print pattern in C

You will be able to :

  • >> Design any kind of pattern
  • >>Understand element of pattern designing
  • >>Understand patterns
  • >>Understand loop in c
  • >>Understand Sequence analysis

What is Pattern?

A pattern is set of  same or different kind of things that represent definite geometrical shapes or size.

Geometrical shape can be 
  • Triangle
  • Square
  • Pramid
print pattern in c
If you look above picture than difinetly you will find repetition of shapes or color in definite manner .

 It's example of pattern.
For Creating sucessfull Pattern , You must know

  • Loop
  • Element of pattern
  • Sequence analysis of pattern

Loop

loop are the control statement .

They are used when programmer needs to execute certain part of program for definite repetation

Different kinds of loop are
  • For loop
  • While loop
  • Do while loop
Among these for loop is used when the number of repetition is known.

Although while and do-while loop can be used while number of loop is known but it is a bit complex

As above explained Pattern contain certain repitation and that is known , so we will use for loop for building patterns

Syntax- for loop

 for ( init; condition; increment ) 

{

 statement(s);

}
Here is the flow of control in a 'for' loop −

  •  The init step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not required to put a statement here, as long as a semicolon appears.
  • Next, the condition is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and the flow of control jumps to the next statement just after the 'for' loop.
  • After the body of the 'for' loop executes, the flow of control jumps back up to the increment statement. This statement allows you to update any loop control variables. This statement can be left blank, as long as a semicolon appears after the condition.
  • The condition is now evaluated again. If it is true, the loop executes and the process repeats itself (body of loop, then increment step, and then again condition). After the condition becomes false, the 'for' loop terminates.

Flow Diagram-for loop
for loop

Element of Pattern

There are number of element that should be well understood before building a pattern.

Number of row and column

Number of column represent number of repetition of first loop first loop with five-time repetition.
star pattern
Code of above program contain

#include  
int main()
{ 
 int i, j;
 for(i=5;i>=1;i--)
 {    //other code 
 }
 return 0;
}

Similarly each row are handled in each repetation of first loop.

Character used

Number of different types of character denote the number of loop inside first loop.i.e nested loop.
star pattern
In above pattern we have to print only '*' , so it will have only one nested lopp.
pyramid pattern
But in above pattern it contain two nested loop with other for easy.

Sequence analysis

star pattern
It is very important and easy to analysis pattern

This is the combination of * and blank space.  we have to  identify that in which position we need to print *and don't worry about the blank spaces.

 we can analysis like this

pattern in c
[ "-" represent a blank space][ and n=9]

Step By Step Solution

1.this program is a shape of matrix. so we need to use two for loop to solve this problem.
 for(i=1;i<=n;i++)
           {
             for(j=1;j<=n;j++)
              {
                  if(condition)
                         printf(" *");
                        else
                         printf("  ");//blank space
                   
              }
             printf("\n");
           }
2. ith 1st and n(9)th index jth 1st and n(9)th index you see. each position we need to print '*' . in side loop condition we can write it as..
      if(i==1 || i==n || j==1 || j==n)
         printf(" *");
       else
        printf("  ");
then output come like box.
star pattern
3. now we need to draw like:
star pattern
here we can see it's printing * where-where ith index and jth index are equals except middle mean [(n/2)+1=5] so we can write code for this:
        if(i==j && j!=(n/2)+1)
         printf(" *");
       else
         printf("  ");
4. Now last pattern, reverse of step(iii) pattern.. ex:
pattern in c

5. so here we can analyse it's decreasing order of j index 9,8,7,6,4,3,2,1 except middle means [n/2+1=5] For this we can write the condition:-


       if(j==(n+1)-i && j!=(n/2)+1)
          printf(" *");
        else
          printf("  "); 


In above example we declared the some variation of pattern based on condition... Even we combined 3 and 4 condition then we will get output like:

pattern in c


condition:
       if(i==j && j!=(n/2)+1 || j==(n+1)-i && j!=(n/2)+1)
          printf(" *");
        else
          printf("  ");


And finally Even we combined this 5 with 2 then we will get output like: Final Example:

star pattern
so final code is:


#include
#include

int main()
{
 int n , i ,j;
 
 printf("Enter number: ");
  scanf("%d",&n);
//first loop
 for( i=1;i<=n;i++)
 {
  for(int j=1;j<=n;j++)
   {

   if(i==1 || j==1 || i==n|| j==n || i==j && j!=(n/2)+1 || j==((n+1)-i) && j!=n/2+1)
   {
        printf(" *");
     }
    else
         printf("  ");
  }
  printf("\n");
//next line 
}
//pattern end
 getch();
}
pattern code download

SUMMERY

  1. A pattern of numbers, star or characters is a way of arranging these in some logical manner or they may form a sequence
  2. Some of these patterns are triangles which have special importance in mathematics. Some patterns are symmetrical while other are not.
  3. Creating a pattern involves how to use nested loops properly, some pattern may involve alphabets or other special characters. Key aspect is knowing how the characters in pattern changes.
  4.  pattern is set of  same or different kind of things that represent deifinite geometrical shhapes or size.
  5. the important element of pattern is it'e order or sequence.
  6. you must be able to recognize order or sequence of pattern inorder to build it.
    Below video can be helpful for understanding Pattern
    Download above tutorial for offline use:
    c pattern download

    DO NOT MISS OTHER C PROGRAMMING TUTORIAL

    * indicates required


    You can Browse related article below for more information and program code related to pattern

    Does above is helpful , Post you views in comment