About Programming - Start

xiaoxiao2021-03-06  19

About Programming - Start

Author: Wang Liang (RobinKin)

Programming, what is it? what's the point?

First assume that you are a schoolboy, the teacher said, "Yesterday we learned the addition, today I came out the topic,

1 plus 2 plus 3 has been added to 100, what is the answer? Does anyone know? "

Then, because you are not Gauss, you will not invent "differential number and formula" (a mathematical term, you will learn to get in junior high school)

However, no problem, you can use this method to calculate this topic.

So, open a text editor on your own laptop, write this paragraph

#include using namespace std;

INT main () {int sum; for (int i = 1; i <= 100; i ) {SUM = SUM I;} cout << sum;}

Then, you saved this file and named Sum.cpp and played two commands, gcc -o sun sum.cpp./sum

So you just see the answer to the question of your teacher's question 5050

The teacher is very happy, saying, "answer the correct!"

OK, you are not Gauss, but you are doing as good as him.

Let's take a look, how do we command your computer to help us solve this "mathematical problem"

Let's take a look at our main commands under the computer, that is, the paragraph:

#include using namespace std; // These two paragraphs are to make the computer to prepare, similar "I want to start the nail, please give me the hate"

INT main () // This sentence can be understood as that "Let me teach you how to do it, please stop my order" {int SUM; // I want to count a number, I name For SUM, start it is 0

For (int i = 1; i <= 100; i ) // Put the number from 1 to 100, sequentially add to SUM {SUM = SUM I;} Cout << SUM; // Print SUM Digital printing on the screen}

This is the process of our command to the computer, but the computer does not know English, just like Americans don't know Chinese.

So we still need an translation, there is a very famous translation name called G

Let's let G to help us translate our orders we have just played.

Enter the following command line G -o sum Sum.cpp

In this way, we translate the Sum.cpp in English into a computer that the computer knows, the name is SUM

Then you can make your computer work according to our command.

Such a simple question, the computer is very fast, no one second, it tells us that the answer is 5050

As for the G this translation of the 来 龙, the length of the party, the next time: P

转载请注明原文地址:https://www.9cbs.com/read-46231.html

New Post(0)