Computer Programming Learning Part-02||Week-02||Use of For Loop in C++ Programming.

in Steem4Professionals6 months ago (edited)

Steemian Friends,
Today, I will write Computer Programming Learning Part-03. Today, I will show the use of For loop in C++ programming. I am slowly learning C++ programs one by one and writing them. One day, I will create a project with a C++ program. Hopefully, everyone will be with me after reading my writing. So, let's start the program.

Programming Learning Part 03.png
Design By Canva

I first write a C++ program on paper using a For loop. The first line through the program will output from one to six. Then, I use a for loop to decrement by one on the following line. In this way, the program will be closed one by one. The entire work will be done through a For loop.

IMG20240513152043.jpg

IMG20240513155827.jpg

Step 01:

I first open the Code Blocks program. Then I click on File. Then click on Open and, click on Empty File and take out a new page. It is shown in the image below.

1.png

2.png

3.png

4.png


Step 02:

Then I first write the Header File and Main function of the program. In C++, these two parts are always written at the beginning of every program. I have written it below.

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


Step 03:

Then I write two variables to declare two integer numbers. Integer numbers will sit in these two. I have written it below.

int i, j ;


Step 04:

Then I wrote the program for the For loop condition. Here, we give the value i = 6 and condition to output numbers from 1 to 6. Then, the following line will decrease by one number. Thus, the loop will continue until one. The For loop is shown below.

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


Step 05:

Then, I will write a program to view the output. I also did this with a For loop. The first line will show output from one to six. The following line decremented by one will output numbers from one to five. In this way, the lines in our output will be reduced one by one. It is written below.

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


Step 06:

Then, we complete each loop with a second bracket. Then I ended the program with Return 0. Then I clicked on the run option of the program and saw the output. If there is any error in the program, the error will be shown in red at the bottom. It is shown in the picture below.

5.png

Step 07:

Then I see the output part. The first line of output shows numbers one through six, then the second line decreases by one to five. Thus showing the output decremented by one per line. The output looks like a pyramid. The output is shown below.

c++ output.png
Program Output

Blue line.png

Link to my previous post:

Part-01

Part-02

Blue line.png

Steemit.com.png

image.png

Sort:  
Loading...

Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
image.png
please click it!
image.png
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)

The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.

Coin Marketplace

STEEM 0.18
TRX 0.16
JST 0.029
BTC 76491.72
ETH 3050.14
USDT 1.00
SBD 2.62