Computer Programming Learning Part-02||Week-02||C program to add numbers from 1-50.
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.
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.
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.
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.
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()
{
}
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;
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)
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;
}
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);
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.
This is my Twitter share link :
https://twitter.com/mahadih83660186/status/1786811205505765767?t=gZz4hVwX2lyrz210vG18lA&s=19
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.
Upvoted 👌 (Mana: 6/8) Get profit votes with @tipU :)
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.
Thank You Dear Ma'am....