Quick Tutorial

C Quick Tutorial -- Let the Computer Talk

Congratulation you find us!!! We offer the quick tutorial for C language.

Let the Computer Talk

Why are there computers? Everything the great humans invented is to help us improve our lives. The computer is also a tool to help us. Think about it, if you now want a computer to help you do something, what do you need to do first? Is it necessary to communicate with the computer first? Then communication needs to rely on a language. Body language, Chinese, English, French and German can be used to communicate with people. If you want to communicate with a computer, you need to use a language that the computer can understand. The “C language” we learn is a kind of computer language. In addition to C language, computer languages ​​include C++, Java, and C#. C language is a relatively simple computer language, more suitable for beginners. All computer languages ​​are interlinked. If you can master the C language proficiently, then learning other languages ​​will become easy.

Since the computer is a tool made by humans to help humans, it is obviously very important to let it speak and tell us what it knows.

Let’s solve the first problem: How to make the computer speak?

Recalling that year, when we first came into this world, what was the first sentence we said? It shouldn’t be “Hello!”, “Have you eaten?”… This will scare your parents!

Along with the cry of “wa wa wa”, we came to this wonderful world, and now we also let the computer “cry once”. In this place, there are two ways for the computer to tell us what it wants to say: one is to display it on the monitor screen; the other is to emit sound through a speaker. Just like when we have something to say, one is to write it on paper, the other is to speak it with our mouth. At present, it is more troublesome to let the computer use speakers to output sound, so another method is adopted, which is to use the screen to output “wa wa wa”.

printf("wa wa wa");

Here is an unfamiliar word called printf. Don’t be frightened by it. You don’t need to figure out what its essential meaning is at present. Just remember that it is the same as “say” in Chinese and “say” in English. However, it is just a word that controls the computer to speak. The () immediately after the printf is like a mouth, and put the content to be said in this “mouth”. There is one more thing to note here. There are "" on both sides of “wa wa wa”, which is what the computer needs to “speak”. Is this very similar to our Chinese? Finally, there must be an end symbol at the end of a sentence. In Chinese, a period is used to indicate the end of a sentence; in English, a period is used to indicate the end of a sentence; in computer languages, a semicolon is used to indicate the end of a sentence.

Note: Every sentence of the computer is a sentence. So, what if you are asked to write a sentence and let the computer say “ni hao”?

    printf("ni hao");

Now we let the computer run this statement. It needs to be explained here, just input printf (“ni hao”);, the computer can’t recognize it, you need to add a frame. The complete procedure is as follows:

    #include <stdio.h>
    #include <stdlib.h>
    int main()
    {
          printf("ni hao");
          return 0;
    }

Here

    #include <stdio.h>
    #include <stdlib.h>
    int main()
    {
          return 0;
    }

Is must for all C framework, you don’t need to understand it for a while, now know to have the can, later to speak in detail its use.But one thing, we write all similar to the printf statements in the future are to write in {}. You need to let the computer run we just write program. If you let the computer run our writing (in fact we write is a C language program), you need a special software, it is called “C language compiler” [1], there are many kinds of “C language compiler”, here are a relatively simple software, called “aha C”.

We use Codeblocks. In Windows: codeblocks-20.03mingw-setup.exe from Download Page In Mac: CodeBlocks-13.12-mac.zip from Download Page Codeblocks Note If you don’t wish install any software, you can run your program online. e.g. online_c_compiler

The Steps for installing can be don everything in default: Select the “Console Application” and “Go” Select “C”

Type the project name. We use “aha”; Make sure you give a path. Then finish.

Now you have the project. Change “Hello World” to “Aha”.

Then click “Build and Run” As we explained, the build convert your language to machine language. Then we let the machine run the compiled stuff, the run step.

I need colorful output!

In section 2 of this chapter, we learned to let the computer speak printf statements should be used.Can be found, the computer, “said.” the words are all black white, actually the output of the computer can be a color, we together and see it.

Note that this code can only be compiler running under the Windows operating system.If you are using the book recommended by C language software “C” aha, so your code can run successfully for sure.Take a look at how to make color.

Please try to enter the following code and running, see what happens.

    #include <stdio.h>
    #include <stdlib.h>
    int main()
    {
      system("color 5");
      printf("wa wa wa");
      system("pause");
      return 0 ;
    }

The base of color is still dark.The color of the text, however, have been turned into the “purple”, is in the following lines of code.

    system("color 5");

In this sentence, “5” on behalf of the “purple”, you can try other Numbers, and see what are the colors. Since the color of the word can change, so the background color can be?Try the following code:

    #include <stdio.h>
    #include <stdlib.h>
    int main()
    {
        system("color f5");
        printf("wa wa wa");
        system("pause");
        return 0;
    }

The above code in front of the original 5 added a f, f here on behalf of the background color is white.

Then set the background color and text color, the color followed by two digits, the first number said the background color, the second number representing text color.If behind the color only added a a number, say only set the text color, background color still use the default color.

To be sure there are actually a number is the hexadecimal, it can only be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f the one.

[aside] “, doesn’t hurt”

Here you learn a new knowledge - into the system.

In modern mathematics, we usually use a decimal, which USES digital 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.After 9 Numbers cannot say, our solution is to use “carry”.Only to 9, for example, Arabic numerals, hence we into one, then the use 0 said, the current is produced by 10 “ten”.Because it is a “dot into one”, so called decimal.

And hexadecimal is “meet hexadecimal”, namely using 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.0 ~ 9 is the same as in the decimal, but the “ten” in capital letters in hexadecimal A said, and so on, “15” in hex F use capital letters to indicate.F is “hex” in the last one, so the number can’t say “16”.So we are just in the decimal said not just into a old way, the current should be represented by 0.“16” in hexadecimal said to 10.27 “in the same way,” said 1 b in hexadecimal.

Many dynasties in ancient China, is made for everyday count hexadecimal, for example, the phrase “well” from allusions hexadecimal;And algorithm is above 2 beads in ancient China, the following 5 beads.If each beads represent Numbers 5 above, the following each beads represent the number 1, then every one of the most important matter is 15, 15 is the maximum cardinality hexadecimal.When using abacus count is greater than 15, we need to “carry” on the abacus.

In fact in our modern daily life, is not all “decimal”, for example, 60 seconds to 1 minute, 60 minutes to 1 hour, is to use the 6 decimal.

Report problems to us

Hi, if you find something need improved. Please feel free to contact us feedback. We will buy you a coffee if your advise is adopted. Thx.