Computer Programming Learning Part-02||Week-02||C program to add numbers from 1-50.

in Steem4Professionals2 months ago (edited)

Steemian Friends,
Today, I will write my Computer Programming Learning Part-02. In Part 01, I wrote a C program to add two numbers and showed the output. Today, I will write a C program to add numbers from 1 to 50 and show the output. I hope everyone will like and benefit from my learning part-02.

Programming Learning Part 02.png
Design By Canva

I will gradually learn big programs with small programs. Then, I will create a project with the program. Hopefully Steemian friends will read my learning parts. So, let's start programming today.


Step01:

I first wrote the C program on white paper. I will write the program on the computer from the white paper and see the output. Today, I will show the use of a while loop in my program. Several loops are used in C programs. Through today's program, we will learn about the use of a while loop.

IMG20240504223142.jpg


Step02:

I first open the Code Blocks software to write the C program. Then, I click on the File option, go to New, and click on Empty File to open the page to write a new program. The program is shown as a red block in the image below.

1.png


Step03:

First, I will write the Header File to write the C program. Then, I write the main function. Then, write the structure of the program. These three parts are first written in the C program. Below, I have written these three parts.

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


Step04:

Then, I will declare the variable. Here, the variable will be an integer number. Declare one variable as X and another as sum. It is shown below.

int x, sum;
x = 1;
sum = 0;


Step05:

Then, I will use a loop in a C program. Today, I will use a while loop. I can use a for loop if I want to add numbers 1-50. Below, I have used a while loop.

while(x<=50)


Step06:

Then I will show the working of the while loop. Here, I will add the integer number sum and the value of x under the while condition. If the while condition does not exist, it will stop working. Then, we add one to the value of variable x to signal the next step. It is shown below.

{
sum = sum+x;
x=x+1;
}


Step07:

Then, I will write the program to view the output. I have written a program to add numbers from 1 to 50. If I want to add numbers from 1 to 100, then I have to write 100 instead of 50 in the while loop.

Printf ("Result : %d\n",sum);


Step08:

Then return 0 or not will not be a problem. Then, I click the Run button to run the program. Then, from the output page, I see the program's output. It is shown as a red block in the image below.

2.png

3.png

4.png

Blue line.png

Steemit.com.png

image.png

Sort:  

Upvoted. Thank You for sending some of your rewards to @null. It will make Steem stronger.

@tipu curate

;) Holisss...

--
This is a manual curation from the @tipU Curation Project.

TEAM BURN

Your post has been successfully curated by @inspiracion at 45%.

Thanks for setting your post to 25% for @null.
We invite you to continue publishing quality content. In this way you could have the option of being selected in the weekly Top of our curation team.

Team Burn (22).png

Burning STEEM by sending it to the @null account helps reduce the supply of STEEM and so increase its price.

 2 months ago 

Thank You Dear Ma'am....

Posted using SteemPro Mobile

Coin Marketplace

STEEM 0.19
TRX 0.12
JST 0.029
BTC 60808.77
ETH 3368.54
USDT 1.00
SBD 2.47