Computer Programming Learning Part-02||Week-02||Use of For Loop in C++ Programming.
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.
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.
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.
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()
{}
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 ;
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--)
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");
}
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.
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.
Program Output
Link to my previous post:
Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
please click it!
(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.
This is my Twitter share link :
https://twitter.com/mahadih83660186/status/1789961789502824672?t=HPO7WQ0N4VX2_vpV_zd5Kw&s=19