New to Nutbox?

Computer Programming Learning Part-09||Project-02||Creating patterns with C++ programs.

7 comments

mahadisalim
73
15 days agoSteemit3 min read

Steemian Friends,
Today, I will write Computer Programming Learning Part-09. I will show you how to create a pattern with a C++ program. Hopefully, everyone can create patterns after seeing my C++ programming techniques.

Programming Learning Part 09.png
Design By Canva


Step01:

I first wrote the C++ program to create the pattern on white paper. Then, I wrote my program on the computer and got the output. Because I wrote on white paper, I was able to find the program's mistakes easily.

IMG20240901171723.jpg

IMG20240901172248.jpg


Step02:

I opened the code blocks software to write C++ programs on the computer. Then, I clicked on the File option. Then, I clicked on the Empty File option and started writing the program, which is shown as a red block in the image below.

1.png

2.png


Step03:

Then, I declare the C++ program's header file and main function. The header file and main function must be declared at the beginning of every C++ program. Below, I have shown the header file and main function declared.

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


Step04:

Then, I declare an integer-type variable to create the pattern. Here, we have declared n, row, and col variables. Below, I have declared an integer variable.

int n, row, col ;


Step05:

Then, I wrote the program to input the value of the pattern creation variable. Here, we will type the value of N. Let the program's output give the value of N. I have written the program below.

Printf("Enter n = ");
Scanf(" %d",& n);


Step06:

Then, I used a for loop. First, I passed the value of row 1 through the for loop. Then, I compared the row's value with the value of n. If the row's value equals the value of n, then the condition will be incremented by one. Below, I have written the program.

for(row=1; row<=n; row++)
{


Step07:

Then, another for loop was used. Through this loop, we first set the column's value to 1. Then, the condition will work by incrementing by one until the row value equals the column value. Below, I have written the conditions for the loop.

for(col=1; col<=row; col++)
{


Step08:

Then, I wrote a program code to view the output, which will show as output if the above condition works. I have written the program below. Write the following code to view the declared part output of every C++ program.

Printf("%d", col);
}
Printf("/n");
}


Output:

After writing the C++ program, I clicked on the Run option. Then, a black page showed the output. I input the value of n here as 20. Then, I saw the output in pattern form. I didn't get any error while viewing the program's output. I am very happy to see the program's output. I hope you, too, will be successful in writing the program.

10.png

20.png

30.png

40.png

Blue line.png

Link to my previous post:

Part-01Part-02Part-03Part-04Part-05Part-06Part-07Part-08

Blue line.png

Steemit.com.png

image.png

Comments

Sort byBest