Programming C: Posts 1 – Hello World
Updated on 09/01/2018
Content
1. Introduction to Programming
Surely you have been exposed to computers, more or less the phone and use apps or games on it such as Word, Office Excel to work or use Chrome, Firefox to Facebook, Google, Facebook and Google are major software.
You imagine your programming is the process of creating software, Such applications. You create applications for others to use, work; you create the game for others to play, make a website for others to access. Nghĩ đến đây đã thấy hứng thú rồi 🙂
Để làm ra được phần mềm (hoặc game, website) then we must teach the computer how to work or otherwise put the rules that we wish to computer to perform as you press up on the character to jump up, press the button to the left, then the character will go to the left.
Like teaching someone to do what you have to say to them or write letters to give them read and from which they can understand what you say. Putting these rules into the computer so that it understands what you want to do that follow, too, you should write requirements that follow a specific syntax that's called programming language.
Programming language like Vietnamese to Vietnamese people communicate and understand, for British English, America and many other countries, … programming language it is the language to speakers for computers to understand. Now there are many different programming languages such as C, C , Java, C #, PHP, python,… each language has its own advantages and disadvantages, and has applications in certain areas.
2. Programming C
C programming you simply use C programming language to create software.
Each software or program called (Computer Programs) will be written by C language with a natural or files with certain rules of language that we will gradually learn.
3. Installation tool
3.1 Settings
To programmable C, you need to install the gcc or g ++ shifter. However, to ease the current multiple integrated software (or called development environment – HERE) we can easily.
- For you Windows users can download Dev-C++ or Code::Blocks installation and we can use immediately to write simple programs.
-
For you to use Linux (ubuntu, Linux Mint,…) can be installed by opening a terminal and run the following command to install:
sudo apt-get install build-essential
After running the above command, you can open any text editor to code (as gedit, vim, hay sublime-text,…) then translated, program run by the terminal.
Or you can completely download and install Code::Blocks Linux to use very convenient, or use the command set:sudo apt-get install codeblocks
You can view more details Programming C / C on Ubuntu (Linux) in his blog
For ease and consistency in process, he would use the Dev-C ++ nhé.
3.2 Basic introduction about Dev-C ++
For easy visualization, you open up Dev-C ++ will see the interface as shown below (Current version you are currently using is 5.11, you can use the other copy will be a bit different, but will not significantly).
In the image above, some parts himself marked by the meaning behind:
1. Button to create a new file
2. Button to open a file has
3. Button to compile and run programs
4. Area code editor (program code)
5. Sorry if the display area.
4. Created the first program
Now you can write the first software program to test.
B1: Create 1 new file.
B2: Type or copy the following code into the editor.
#include <stdio.h> int main() { printf("Welcome"); return 0; }
B3: Saved with the file name Test.c or Test.cpp
B4: Click the button to run the program and you will see a black screen pops up as follows:
In which you can see the word Welcome showing up, it is the words are printed out using command printf. The lower part is horizontal line by Dev-C self-generated.
Mình giải thích một chút về code:
- Current 1: Chứa phát biểu tiền xử lý
#include <stdio.h>
. Vì trong chương trình này ta sử dụng các lệnh trong thư viện của C là printf, so you need to declare the function library to tell the C compiler know. If you do not declare the program will error. Library stdio.h stands for standard input output (std – in – the) là thư viện nhập xuất chuẩn). -
Current 3: **
int main()
is the main component of any program C. Mọi chương trình C đều bắt đầu thi hành từ hàm **main. Brackets()
said this is the function block (function). Hàm main() có từ khóaint
said first function returns integer values (int). -
Current 4 and 7: pair of braces
{}
limit of a function body. Body functions start with { and ends with }. -
Current 5:
printf ("Welcome");
, instructs the printer to the string in quotes""
. This line is called a statement, end a command in C is the semicolon( ; ). -
Current 6:
return 0;
Returns the integer value is 0 according to the initial right to declare int main().
Noted:
- In his program not use conio.h library as in the standard C library does not have this, and therefore also not be used getch() to stop the screen they were replaced by command
system("pause");
in the library stdlib.h - when used
return
to return the value of the function, then you can skip this command program is still running, but the standard is wrong, returns 1 also wrong, summary is returned 0. If returns 1 others do not, the computer system will understand that your program after running generates need that error.
Now open the folder containing the file Test.c you just created, you will see a file named Test.exe (called exe), this is the executable program. Now if you want you can click on the .exe file is run the program or you can copy the exe file to another computer, you could still run, it's like you to copy games from one computer to another so.
From here we have:
- File Test.c the files we create and write commands to the computer understands, This file called source files.
- File Test.exe file is generated when we press the button Run, This file called executables.
Noted: The following programs we do will primarily run on a black screen as above (called the console – Read the 'worm'), but no nice interface but this is the core of programming, good learning this section we can do the program with a graphical interface and other languages and most rely on this core.
Exercise: Write a program that prints out your name, your parents or lovers if. Do not forget to show off to friends again.
Oh do s to run a program?
Busy press F9 or secondary buttons 3 (4 adjacent color) in toolbar nhé.
But e F9 is used Dell computer is powered dimmer sir node
Ở bên trên có hình chỉ rõ nút chạy đó em. Chính là nút số (3)
bạn ấn đồng thời shift + F11 ấy là đc
F11 nó vừa dịch vừa chạy chương trình luôn
Bấm ctrl+F9 đó e
g++.exe has stopped working là sao v anh ?
Kids press f9 it was v
This can be faulty program or your installer problems.
Oi the League Ban , I need to create diagrams 30×30
Depending on the input that will be different scheme
Input là:
Int. INT. Char
21 12 @A
22 14 @c
……………..
It's like graph graph (x,and)
Then they print out if there char where the print hok *, even if it does print A
Output:
***********
**********The
****c******
I wrote like this:
1. First series if x30 same to y
2. For (row=0, row<=30, row++)
For (col =0, with<=30, col++);
For ( row=x,
If row =x && and row =
Printf(tank)
Else printf(*)
Nhung after print, moi input is different maps,
So loop fails to Hok
Waiter ! Why in Visual Stu. 2013 Ultimate Kids use the function “getch” to stop the program is it error “error C4996: 'Getch': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch. See online help for details. ” World ? How to negate ạ ?
Instead, use the ISO C++ conformant name: _getch
For her main questions() với int main() What difference have not ?
Of, no main nhé. Only main void or int main. And now it is the benchmark write int main nhé you.
According to him, the new person should learn C or C ++ before ạ ?
If you see new programming you should learn Java before.
Previously they also find some Tut or Slide on Java and, but most of it written quite vague look not understand :3 But when his view on C, I see a lot more understandable :3 Thank you ! =)))))
My brother asked me to have the results printed out the exact value to the second digit decimal part must be how he
You use the% 0.2f
Why Java beginners should learn before ạ? -_-“??
Since Java is the language object huoqngs. It is close to reality
My brother was a student a postal, The most complete implementation of the new language c, but really I do not know anything, as some 0, For Grades 1-12 I do not touch the computer, He can advise you how to learn how to access and understandable language learned this c ko sir, thanks a
Is easy to learn how to keep learning, Where it asked questions.
at right, visual basic programming increased to cascade :3, trying to Vietnam
Waiter, dev C and Visual C different public
so when you install Dev C spacing vs bulkier too wide apart
at the new Kids learn about programming and want to learn C ++ should always expecting him to show sir
It is just only editor, inside it was a little different about libraries. Depending you want to learn at Dev-C or Visual C also.
ad for you to ask good at programming, I can do what job ?
Do Programmers, makes software for PC, phone running nhé.
Lập trình có hồi nào nạp vào dt chết may luôn ko a – e daq Sưa ĐT va Tinh hoc them lap Trinh a
Không chết máy được đâu 🙂
Bạn cho mình hỏi làm sao mỗi lần bấm vào chuyên mục nào là nó sẽ hiện ở thanh slidebar với dưới bài viết danh sách bài học vậy bạn. Mình cảm ơn nhiều.
Cái này mình code thêm để có. Bạn có thể tìm một số plugin của wordpress để làm việc này 🙂
you yourself would like the code to dc ko sir. His look but do not find your plugin
His code it has customization and filtering by category. This code is located in the file single.php, placed after article. I have it on id =”sidebar” so that it is formatted as the blog's sidebar. You see the code here
Copy this paragraph put in single.php dc dear. What do you know dc plug as V not you.
You try this
entering any number to the result a2, a3, a4 do not know how to enter the squared, Maybe not every person a * a * a game
Enter the print result done after all. a^2 = a*a. ^^
He asked me void main () other than int main () wherein the teachers they all use void main()?
Was 2 Different spellings severance, IDE or use the old days but now switch to int void.
Star e .c file export that k attached .exe file, right hix :'(
You must run the new exe file it nhé.
int main() and void main() Where it differs, Bro
let me ask IF THIS SOFTWARE PROGRAMS proficient then you can use it to control the computer OR CREATE SOFTWARE IS NOT OWN SELF, EVEN MORE HACK.
This depends on your ability.
Như e mù hoàn toàn về lập trình thì đây chính là bắt đầu và kiến thức căn bản phải không ạ??
Right.
sao em chạy mà nó lại lỗi là sao anh ??
Hỏi thế thì a chịu.
Em nhờ gửi code chút ạ. Hihi
#include #define _CRT_SECURE_NO_WARNINGS using namespace std; int n, m, choChoi[21], goiUuDai[32][21], to, the, linhKien[21], visited[32], sum, minCost, daCo[21]; void deQuy(int step){ if (step==m+1) { for (int i = 1; in <= l; i ) { if (daCo[linhKien[in]]==0) { sum+=choChoi[linhKien[in]]; } } if (sum<minCost) { minCost = sum; } else { for (int i = 1; in <= l; i ) { if (daCo[linhKien[in]]==0) { sum-=choChoi[linhKien[in]]; } } } return; } for (int chon = 0; chon minCost) { visited[step] = 1; sum-=goiUuDai[step][0]; deQuy(step+1); } else { for (int i = 2; in <= goiUuDai[step][1]+1; i ) { for (int j = 1; j <= l; j ) { if (goiUuDai[step][in]== linhKien[j]) { daCo[goiUuDai[step][in]]++; } } } deQuy(step+1); for (int i = 2; in <= goiUuDai[step][1]+1; i ) { for (int j = 1; j >T; for (int testCase = 1; testCase <= T; testCase++) { minCost = 0; for (int i = 0; in < 32; i ) { for (int j = 0; j >n; for (int i = 1; in >choChoi[in]; } cin>>m; for (int i = 1; in >goiUuDai[in][0]; cin>>to; goiUuDai[in][1] = k; for (int j = 2; j >goiUuDai[in][j]; } } cin>>the; for (int i = 1; in >linhKien[in]; minCost + = choChoi[linhKien[in]]; } sum = 0; deQuy(1); cout<<"#"<<testCase<<" "<<minCost<<Endl; } return 0; }
Brother he had lessons about object-oriented programming ( C ) no ??
Themselves do not agree.
Let me ask why when I go to the folder to open the .exe file, it just flashes and then turns off. I still can't use the command to stop the screen
So it can't stop. Can you try to see if the command stops correctly??
Admin, I press F5 to run but it shows the screen for 1 second and then it turns off?
You read the second post 2 nhé.