This series of articles will be taught in easy-to-understand dialogues that will cover common problems for beginners. This series will continue to be updated, including the use of dialogue in other languages as well as in the real world. Basic programming language teaching is applicable to the zero-based students, and the real world curriculum will be gradually updated.

If there is something you want to learn, you can leave a message in the comments section and keep updating according to your request. I’ll update the next one if I get 100, 000 likes. (Definitely not, and more.)

If you have any questions, leave them in the comments section.

If you like the content, welcome to follow me, comment, like, favorites, this is very important to me, thank you ~

directory

If I ask basic questions in a big group, no one will listen? “Peep big talk chat record to learn C language” (2) I said programming is easy to defy you? “Peep big talk chat record learn C language” (3) code are in love don’t you know? “Peep big talk chat record to learn C language” (4) originally I would program “peep big talk chat record to learn C language” (5) played a game I learned a programming knowledge? “Peep big talk chat records to learn C language” (6) told me that programming is difficult to stand out to me “peep big talk chat records to learn C language” (7) the next article tell you who is the cowherd “read chat records to learn C language? Too dish” (8) Cowherd and weaver girl unexpectedly have a child?

Author’s brief introduction

Author name: 1_bit introduction: CSDN blog expert, 2020 TOP5 blog stars

🐰 Xiaoc: Xiaoyuan, let’s continue our class.

👸 Xiaoyuan: Ok, xiaoyuan, I can’t wait. 😉

🐰 Small C: I would like to ask you a few questions first, do you think our variable can store integer type, what else can store similar?

👸 Xiaoyuan: Ah… I don’t know. I don’t know. 😱

🐰 small C: That I change a question to ask you, mathematics in addition to integer still have what number?

👸 Yuan: And decimals.

🐰 Little C: What about decimals that can be put into integer variables?

👸 small yuan: should, can’t? 😭

🐰 small C: can put, but will give a problem. Int is an integer type, but we have another type that represents a decimal, and of course the decimal is in quotation marks, so we use that for your convenience.

👸 xiaoyuan: What is that with what to express decimal?

🐰 small C: Use float to represent decimals, but in C we should call it floating point.

👸 xiaoyuan: that is not equal to creating a floating point variable. 😥

#include<stdio.h>
#include<stdlib.h>
void main(a){
	float a=3.14;
} 
Copy the code

🐰 small C: Yes, then you write a program output display try.

👸 small yuan: I always feel you pit me, you see is not so. 😩

#include<stdio.h>
#include<stdlib.h>
void main(a){
	float a=3.14;
	printf("%d",a);
} 
Copy the code

🐰 Small C: You try first.

👸 Xiaoyuan: Ah, why so. 😓

🐰 little C: That’s because %d is also an integer and we should use %f instead of %d. Try this instead.

#include<stdio.h>
#include<stdlib.h>
void main(a){
	float a=3.14;
	printf("%f",a);
} 
Copy the code

👸 small yuan: wow, successful, that why behind have a few 0 follow? 😉

🐰 small C: This is because 0 is its default display digit, which we can ignore. Now that you’ve learned about the different types of representations, I’m going to show you how to add two numbers together in C and get the result. Look at the following program.

#include<stdio.h>
#include<stdlib.h>
void main(a){
	float a=3.14;
	int b=10;
	printf("%f",a+b);
} 
Copy the code

👸 xiaoyuan: Huh? Will %f also be replaced by the value of a plus b?

🐰 little C: Yes, when printf is executed, the result of a+b will be computed first, and finally the result of a+b will be displayed at %f.

👸 xiaoyuan: that why is % F?

🐰 Small C: I ask you 3.14+10 is what?

👸 Yuan: 13.14, what’s wrong? 😩

🐰 small C: 13.14 is not a decimal number?

👸 Xiaoyuan: I see, the final result is a decimal, so use %f. No, I should say floating point. 😨

🐰 small C: ha ha ha, yes, let me ask you, I want you to display the value of a+b and b-a at the same time, how will you do it?

👸 Xiaoyuan: HMM… I think… Got it. Look at the code.

#include<stdio.h>
#include<stdlib.h>
void main(a){
	float a=3.14;
	int b=10;
	printf("%f,%f",a+b,b-a);
} 
Copy the code

🐰 small C: good, or quite smart, know to use a comma separated, so there are two values. So let me ask you again if I want to store the results of a plus b and b minus A in a variable, and then print them out what do I do?

👸 small yuan: this can not difficult me, you see the code. 😃

#include<stdio.h>
#include<stdlib.h>
void main(a){
	float a=3.14;
	int b=10;
	float c=0,d=0;
	c=a+b;
	d=b-a;
	printf("%f,%f",c,d);
} 
Copy the code

🐰 small C: it seems that you still can, but your code can be simplified, you see my code you think is not more simplified.

#include<stdio.h>
#include<stdlib.h>
void main(a){
	float a=3.14,c=0,d=0;
	int b=10;
	c=a+b;
	d=b-a;
	printf("%f,%f",c,d);
} 
Copy the code

👸 small yuan: so I also can. 😃

🐰 Little C: You can do that.

#include<stdio.h>
#include<stdlib.h>
void main(a){
	float a=3.14;
	int b=10;
	float c=a+b;
	float d=b-a;
	printf("%f,%f",c,d);
} 
Copy the code

👸 Xiaoyuan: the original can directly create a variable when you can add assignment? ☺ ️

🐰 Little C: Yes, but remember, programs run from the top down, just like you read a book. To use a variable you have to declare the creation beforehand, or our compiler won’t know what it is.

👸 xiaoyuan: well, like reading a novel, inexplicable appearance of a character, if there is no introduction in front of that I do not know him.

🐰 Little C: Yes. Let me show you how to add, subtract, multiply and divide again.

#include<stdio.h>
#include<stdlib.h>
void main(a){
	float a=3.14;
	int b=10;
	float c=a+b;
	float d=b-a;
	float e=b*a;
	float f=b/a;
	printf("%f,%f",c,d);
} 
Copy the code

👸 Xiaoyuan: very easy, with math in the same. 😇

🐰 Little C: Of course, you can also mix calculations.

#include<stdio.h>
#include<stdlib.h>
void main(a){
	float a=3.14;
	int b=10,a1=1,a2=8;
	float c=a+b-a1;
	float d=b-a*a2;
	float e=b*a+a1;
	float f=b/a*b;
	printf("%f,%f",c,d);
} 
Copy the code

👸 small yuan: feel the content of today’s study is very simple, ha ha ha, is not I enlightened.

🐰 small C: today indeed you perform better, make persistent efforts, we will continue to learn tomorrow.

👸 Xiaoyuan: OK, then I go back to practice. 😋

🐰 C: Come on.