当前位置:网站首页>C language final without failing (Part 1)
C language final without failing (Part 1)
2022-06-30 01:04:00 【Hua Weiyun】
Preface
: Everyone, learn from the scum , How do you do ? The exam is coming soon ,c Language has learned ? Don't talk much , Since none of you can , We only talk about dry goods , If you think the blogger is good , Welcome to the article three times , Your encouragement is the biggest gain for bloggers !: sprint 90 Recommend by column 《c Language from 0->1》 In the past, we didn't fail the series :
python Don't go to school ( On )python Don't go to school ( in )python Don't go to school ( Next )
Basic input and output
main Function templates
Due to limited time , Let's just talk about Know what it is , , Don't speak Know why , If you want to know more about it, you can go to the column above Main function template
#include<stdio.h>int main(){ return 0;}This Templates You must remember !!! remember return 0 Don't lose it
Input and output
Due to time , We will only cover the most commonly used inputs and outputs (printf and scanf), Where the dream begins ,
#include<stdio.h>int main(){ printf(" End of term c Language must pass "); return 0;}printf sentence : Output statement , The above code is output on the display , End of term c Language must pass , What we should pay attention to here is to remember printf(" "); Format , One () and ”“, And finally A semicolon
A few escape characters :’\n’,’\t’…… Generally, it is enough to remember these two
#include<stdio.h>int main() { printf(" Autumn mountain code people , handsome !\n I didn't fail at the end of the term !"); return 0;}
\n Line break ,\t Tabulation
Output several common data types
#include<stdio.h>int main(){ int a = 18; printf("%d",a); return 0;}This piece of , We define integer variables a, Then the output . We want to remember What's important is a few “%d%f……”, Let's just draw a conclusion , Now look at this picture :


Focus on remembering , Byte length is OK ,char,int,double,float, Corresponding % Number is , %c,%d,%lf,%f
Input scanf
#include<stdio.h>int main() { printf(" Please enter your age "); int age; scanf("%d", &age); printf(" What is your age %d", age); return 0;}
Look at the picture , It's not hard to find out ,scanf The syntax rule for is :
scanf("% what ",& Variable );
Be careful : & Be sure to remember ,” “ Is a variable type
printf in What is your age %d, Among them %d By age Instead of the output , Output : What is your age 18
Basic operation rules +,-,*,/,%
This one has only ,/ and % Different from mathematics ,% It's surplus ,/ Yes, keep the whole
#include<stdio.h>int main() { int a = 19; int b = 3; int c = a / b; printf("%d", c); return 0;}// Output :6#include<stdio.h>int main() { int a = 19; int b = 3; int c = a % b; printf("%d", c); return 0;}// Output :1Examples of input and output
After the introduction above , I believe you are right to learn c Language has a basic concept , Let's look at it with examples :
- Input integer a,b, Output a+b
- Output ’ a ‘,’ b ‘,’A‘ ,’ B’
#include<stdio.h>int main() { int a, b; scanf("%d%d", &a, &b); printf("%d", a + b); return 0;}#include<stdio.h>int main() { char a = 'a'; printf("%c %d\n",a,a); char b = 'b'; printf("%c %d\n", b, b); char A = 'A'; printf("%c %d\n", A, A); char B = 'B'; printf("%c %d\n", B, B); return 0;}
Remember these numbers, too , And so on ,a:97,A:65
Array
Define a length of 5 Of int Type of the array , Input , And output
int a[5[;a[0] = 1;a[1] = 2;a[2] = 3;a[3] = 4;a[4] = 5;Many computers are made from 0 At the beginning , The first element of the array , Subscript to be 0
Select statement
Common logical operators

if
#include <stdio.h>int main(){ int a; scanf("%d", &a); if (a > 1) printf("a Greater than 1"); return 0;}if…else…
Implementation of conditions if What's in the sentence , Otherwise execution else Later
#include <stdio.h>int main(){ int a; scanf("%d", &a); if (a >= 60) printf(" pass "); else printf(" fail, "); return 0;}if…else if…else
It is not difficult to guess by comparing the above , If … And if … otherwise …
#include <stdio.h>int main(){ int a; scanf_s("%d", &a); if (a >= 60 && a <= 70) printf(" pass "); else if (a > 70 && a <= 80) printf(" good "); else if (a > 80) printf(" good "); else printf(" fail, "); return 0;}expression 1? expression 2: expression 3
It means when expression 1 When it's true , Execute expression 2, Otherwise, execute the expression 3
#include<stdio.h>int main() { char ch; scanf("%c",&ch); ch = (ch >= 'A' && ch <= 'Z') ? (ch + 32) : ch; printf("%c", ch); return 0;}switch sentence
swtich( expression ) { // () Only integers are supported for data types in case Constant 1 : Statement to execute ; break; case Constant 2 : Statement to execute ; break; case Constant 3 : Statement to execute ; break; default: Statement to execute ; break;}Be careful :default, When the above conditions are not met , perform default sentence
Example
- Judgement of leap year
- Determine whether the character is a capital letter , If lower case letters are converted to upper case , Otherwise direct output ( See the conditional expression code above )
// Leap year #include<stdio.h>int main() { int y; scanf_s("%d", &y); if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) { printf("%d It's a leap year ", y); } else { printf("%d It's not a leap year ", y); } return 0;}边栏推荐
- Too voluminous ~ eight part essay, the strongest king of interview!
- Vl6180x distance and light sensor hands-on experience
- Time flies that year
- MySql函数
- Crmeb SMS for program configuration of knowledge payment system
- 2022-06-29:x = { a, b, c, d }, y = { e, f, g, h }, x、y两个小数组长度都是4。 如果有: a + e = b + f = c + g = d + h
- How did the data center change from "Britney Spears" to "Mrs. bull"?
- Outsourcing for 3 years is a waste
- Analysis of IM instant messaging development technology on modern web
- Vant weave - remove (clear) < van button > button component Click to display gray background effect
猜你喜欢

Is the numpy index the same as the image index?

How to create a module in the idea and how to delete a module in the idea?

Outsourcing work for three years, waste a step confused

Sfdp 超级表单开发平台 V6.0.4 正式发布

How did the data center change from "Britney Spears" to "Mrs. bull"?
![[deep learning compilation] operator compilation IR conversion](/img/10/bdcabde772e65eebc93f870f597524.png)
[deep learning compilation] operator compilation IR conversion

81. 搜索旋转排序数组 II

ResizeKit2.NET大小和分辨率独立

Cloud, IPv6 and all-optical network

What if you can't write your composition well? Ape counseling: parents should pay attention to these points
随机推荐
2022-06-29: x = {a, B, C, D}, y = {e, F, G, H}, the length of the two small arrays X and Y is 4. If yes: a + e = B + F = C + G = D + H
快手伸手“供给侧”,找到直播电商的“源头活水”?
What if you can't write your composition well? Ape counseling: parents should pay attention to these points
How to design test cases
利用tsne将不同句子关于相似度可视化出来
Twitter launches the test of anti abuse tool "safe mode" and adds enabling prompt
Experience of C language course design: open source sharing of "push box" course design works
SFDP super form development platform v6.0.4 was officially released
如何在IDEA中创建Module、以及怎样在IDEA中删除Module?
c语言期末不挂科(上)
Time flies that year
岁月匆匆那年
开发者,为什么说容器技术的成熟预示着云原生时代的到来?
【深度学习编译】算子编译 IR 转换
Kwai reached out to the "supply side" to find the "source" of live broadcast e-commerce?
ResizeKit2.NET大小和分辨率独立
Clean, talk, bring children, and get rid of the label of "artificial mental retardation" for the sweeper
数据中台咋就从“小甜甜”变成了“牛夫人”?
Solve the problem of repairing Visual Basic exceptions with excel/wps plug-in of choice financial terminal
Birds in the corn field