Coding

Pattern Programs using numbers, alphabet & symbols

Last Updated on 16/02/23 0
pattern-programs-feature-1.png

What are Pattern programs?

Pattern programming is to write a program to generate a defined and beautiful pattern using Numbers, Alphabets, and Symbols like stars. This is an alternate way to create a type of graphics and also a prominent method to learn programming.

Pattern programs are very popular in the C and Java language especially in their early days when a learner starts to learn to code. It helps to learn programming in a fun and easy way. Pattern programs are very popular in interviews too.

In this post, we will be explaining several pattern programs along with their solution in Havi code. Following are some key benefits of writing pattern programs.

  1. Helps beginners and kids to learn programming in an easy and faster way
  2. Builds logic, problem solving, and algorithm skills
  3. Improves attention to details
  4. Adds fun to coding.

How to write pattern programs?

Patterns are actually pixel drawing or binary drawing.

Imagine you have blank paper and you want to draw a square on it. How will you do that? Easy, no? Very easy though, you will lift your pencil and draw a square.

But what if you want to draw the same square on graph paper (grid paper) having squares of 1 MM? This is not very hard either. You will fill the squares that you want to be part of the square and you are done.

Here is another catch.

What if you can’t go to the pixel of your choice straight away and will have to travel each and every pixel to reach there? Hmmm, a bit more work but not that challenging.

What you will have to do now, is skip the pixels that you don’t want to be part of the lines of the square. That means you are writing 0 (nothing) on those pixels. And once you reach the destination pixel, you will print 1 (a dot). Continue printing 0 and 1 till your pattern is complete.

We can take a similar approach in computers too. The screen is the canvas and there are thousands of pixels on it, exactly as we have on the graph paper.

We will have to travel through every pixel until we reach the pixel we want to start drawing on.

That 1 here can be any of the following

  1. An alphabet, capital or small.
  2. A symbol like a star (*) at (@) hash (#) and others.
  3. A number
  4. A smiley

You feel the screen with 1 (Symbols etc) and 0 (Blank space) and your pattern will come up.

Here we provide a free graph paper for download. You can take a print of this and prepare your pattern first on it before you start coding. This will help a learner to better build the algorithm.

Download Graph Paper

We believe this extensive list of pattern programs will be useful to teachers as a great coding resource and to learners to challenge themselves to code.

Let’s start coding.

1: Toran

You can make this using | and *.

Toran pattern
Constraint:
1) Number of rows and columns of * must not decrease.
2) You can use the print command a maximum of 3 times.

2: Swings

This pattern is introduced by one of the Havi heroes, Jane. You can make this using |, 8 and *.

Swings pattern program
Constraint:
1) Number of rows and columns must not decrease
2) You can use the print command a maximum of 4 times.

3: Ladder

Make this ladder using | and -.

Ladder pattern
Constraint:
1) Number of rows and columns must not decrease
2) You can use the print command a maximum of 4 times.
3) Must use an if..else block.

4: Smiley

This pattern is introduced by one of the Havi heroes, Jane. You can make this using | and *.

pattern with smiley
Idea!
You can try making the smiley using / too.

5: Right triangle using star

This is the legacy pattern program being developed in C, C++ and Java languages for decades. But this (and some other patterns) is always refreshing to do.

right triangle pattern
Constraint:
You can use only one print command to execute this.

6: Right downward triangle using star

right downward triangle pattern
Constraint:
Can use the print command only once.

7: Pyramid

pyramid pattern
Constraint:

Can use print commands only twice.

8: Diamond

diamond pattern
Constraint:

Can use the print command for a maximum of 4 times.

9: Square

There are multiple ways to solve this pattern challenge. (That’s actually a fact for almost all programs) Try solving this with 3 print commands. 4 print commands and with conditions.

square pattern
10: Christmas Tree

Do this christmas tree pattern with a maximum of 4 print commands.

christmas tree pattern
11: Flag

Try making this flag pattern with maximum of 5 print commands.

Flag pattern
12: Boat 1

Why don’t you sail yourself in the boat pattern created by you? But not more than 5 print commands in your code.

Boat 1 pattern
13: Boat 2

And twist your code to alter the boat pattern as shown here. A bit more realistic.

Boat 2 pattern
14: Bucket 1

Code this bucket pattern by using maximum 2 print commands.

Bucket pattern
15: Stumps

The cricket lovers will love coding this stump patterns. You have a maximum of “4 balls to hit this”. πŸ™‚

Stumps pattern
15: Road

A programmer was trying to make something else and ended up making this road pattern. Even a 5 year old could reccognize it as road. Try coding these with maximum 4 print commands.

Road pattern
16: Air pump

And this air pump. Beautiful it is. Isn’t it? You are allowed to use upto 6 print commands for this.

Air pump pattern
17: Bucket 2

This alteration to bucket pattern is done by Abhiram (11). Can you just try to code this?

Bucket-2 pattern
Pattern programs using numbers

Let’s code some wonderful pattern programs using numbers. This is going to be a treat for Maths and statistics lovers.

18: 1 to 10 triangle

This triangle is formed using 1 to 10 numbers. Each of the row start the numbering again from 1 and extends the series by 1 each time. Prepare this using one print command. Just to make the program output readable and beautiful you can use another print command to keep space between two numbers.

Triangle using 1 to 10
19: 10 to 1 triangle

Here here is the Flip! Edit the program to start the triangle from 10.

Triangle using 10 to 1
20: Triangle using same numbers – top to bottom

Each of the row here is made up of only one number. Make this program using 1 print command only. Can use additional print only to make it beautiful.

top to bottom
21: Triangle using same numbers – bottom to top

And now Flip this!! πŸ™‚

Triangle bottom to top
22: Binary triangle 1

Constraint: Maixmum of two print commands. However, this can be done with one print command as well.

Binary triangle 1
23: Binary triangle 2

Constraint: Maixmum of two print commands. However, this can be done with one print command as well.

Binary triangle 2
24: Binary triangle 3

Constraint: Maixmum of two print commands. However, this can be done with one print command as well.

Binary triangle 3
25: Binary triangle 4

Constraint: Maixmum of two print commands. However, this can be done with one print command as well.

Binary triangle 4
26: Triangle using even numbers

Constraint: Can use only one print command.

Even number triangle
27: The floyd’s triangle

Constraint: Can use only one print command.

Floy's triangle
28: Triangle using odd numbers

Constraint: Can use only one print command.

Odd number triangle
29: Up-side-down Pyramid pattern using different numbers

Constraint: Can use only two print commands.

Pyramid using different numbers up-side-down
30: Pyramid pattern using different numbers

Constraint: Can use only two print commands.

Pyramid using different numbers
31: Up-side-down Pyramid pattern using same numbers

Constraint: Can use only two print commands.

Pyramid using same numbers up-side-down
32: Pyramid pattern using same numbers

Constraint: Can use only two print commands.

Pyramid using same numbers up-side-down
33: Rakhi patterns

Here are some nice Rakhi patterns if you wish to code. A great exercises for early learners.

34: Diya pattern

This Diya pattern was created by Pranav(11). Kudos to you. A great exercises for early learners.

diya pattern
35: Havi pattern

One more creative pattern from Pranav. This was created by him as his 100th project submission on Havi Heroes. This needs creativity and high level of attention.

Havi Pattern
Would you like to join Havi’s creator’s community? Join now

Liked this article? Share with your friends

0
0
Your Cart
Your cart is empty
Calculate Shipping
Apply Coupon