当前位置:网站首页>c语言期末不挂科(上)
c语言期末不挂科(上)
2022-06-30 01:02:00 【华为云】
前言
:各位学渣,你们好?马上考试了,c语言学会了?话不多说,鉴于你们都啥也不会,我们只讲干货,如果觉得博主讲的不错的,欢迎给文章三连一下,你们的鼓励就是给博主最大的收获!:冲刺90分专栏推荐《c语言从0->1》往期不挂科系列:
基本输入输出
main函数模板
由于时间有限,我们只讲知其然, ,不讲知其所以然,想要了解的可以去上面的专栏查看主函数模板
#include<stdio.h>int main(){ return 0;}这个模板必须记住!!!记住return 0别丢
输入输出
由于时间关系,我们只讲解最常用的输入输出(printf和scanf),梦开始的地方,
#include<stdio.h>int main(){ printf("期末c语言必过"); return 0;}printf语句:输出语句,上面的代码在显示器上输出,期末c语言必过,这块我们要注意的是记得printf(" ");格式,一个()和”“,以及最后的分号
几个转义化字符:’\n’,’\t’……一般记住这俩个就够了
#include<stdio.h>int main() { printf("秋名山码民,帅!\n期末没有挂科!"); return 0;}
\n换行,\t制表
输出几个常用的数据类型
#include<stdio.h>int main(){ int a = 18; printf("%d",a); return 0;}这块,我们定义了整型的变量a,然后输出。我们要记住的是几个“%d%f……”,还是直接给结论,下面请看这张图:


重点记忆一下,字节长度就行,char,int,double,float,对应的%号为, %c,%d,%lf,%f
输入scanf
#include<stdio.h>int main() { printf("请输入你的年龄"); int age; scanf("%d", &age); printf("你的年龄为%d", age); return 0;}
观察图片,不难发现,scanf的语法规则为:
scanf("%啥",&变量);
注意: &千万要记得,” “中是变量类型
printf中你的年龄为%d,其中的%d被age的实际值代替输出,输出:你的年龄为18
基本运算规则+,-,*,/,%
这块只有,/和%与数学不同,%是取余,/是留整
#include<stdio.h>int main() { int a = 19; int b = 3; int c = a / b; printf("%d", c); return 0;}//输出:6#include<stdio.h>int main() { int a = 19; int b = 3; int c = a % b; printf("%d", c); return 0;}//输出:1输入输出的例题
经过上面的介绍,相信各位学渣也对c语言有了一个基本概念,我们用例题来看:
- 输入整数a,b,输出a+b
- 输出’ 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;}
这几个数字也记住,到时候可以类推,a:97,A:65
数组
定义一个长度为5的int型数组,输入,并且输出
int a[5[;a[0] = 1;a[1] = 2;a[2] = 3;a[3] = 4;a[4] = 5;计算机中许多都是从0开始的,数组的第一个元素,下标为0
选择语句
常见的逻辑运算符

if
#include <stdio.h>int main(){ int a; scanf("%d", &a); if (a > 1) printf("a大于1"); return 0;}if…else…
条件成立执行if语句中的内容,否则执行else后面的内容
#include <stdio.h>int main(){ int a; scanf("%d", &a); if (a >= 60) printf("及格"); else printf("不及格"); return 0;}if…else if…else
对比上面的也不难猜出,如果…又如果…否则…
#include <stdio.h>int main(){ int a; scanf_s("%d", &a); if (a >= 60 && a <= 70) printf("及格"); else if (a > 70 && a <= 80) printf("良好"); else if (a > 80) printf("优秀"); else printf("不及格"); return 0;}表达式1?表达式2:表达式3
意思就是当表达式1为真的时候,执行表达式2,否则执行表达式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语句
swtich(表达式) { // ()中的数据类型仅仅支持整数 case 常量1 : 要执行的语句; break; case 常量2 : 要执行的语句; break; case 常量3 : 要执行的语句; break; default: 要执行的语句; break;}注意:default,当上述条件都不满足的时候,执行default语句
例题
- 判断闰年
- 判断字符是否是大写字母,如果是小写字母转换为大写,否则直接输出(见上面条件表达式代码)
//闰年#include<stdio.h>int main() { int y; scanf_s("%d", &y); if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) { printf("%d是闰年", y); } else { printf("%d不是闰年", y); } return 0;}边栏推荐
- 如何拒绝期末复习无用功?猿辅导:找准适合自己的复习方法很重要
- 利用tsne将不同句子关于相似度可视化出来
- Antd - tree structure: default deployment node attribute failure - Basic promotion
- Outsourcing work for three years, waste a step confused
- Database learning notes (sql03)
- 阿于的彩虹桥
- Yunna | fixed assets information system management, information-based fixed assets management
- Quick Pow: 如何快速求幂
- Seata and the three platforms are working together in the summer of programming. Millions of bonuses are waiting for you
- 元素使用 align-items center 和 overflow auto 之后,部分内容显示不全
猜你喜欢

Newton method (optimization of two variable functions)

在线文本数字识别列表求和工具

Solving plane stress problem with MATLAB

The first unlucky person watching eth 2.0

Programmers with a monthly salary of less than 30K must recite the interview stereotype. I will eat it first!

2022-06-29:x = { a, b, c, d }, y = { e, f, g, h }, x、y两个小数组长度都是4。 如果有: a + e = b + f = c + g = d + h

赛芯电子冲刺科创板上市:拟募资6.23亿元,共有64项专利申请信息

Too voluminous ~ eight part essay, the strongest king of interview!
![Cantilever beam calculation [matlab code]](/img/f6/9a1338e00777e91f6c340eae9d52ba.jpg)
Cantilever beam calculation [matlab code]

Which department should the company's fixed assets be managed? How should the company's fixed assets be managed
随机推荐
HC32M0+ GPIO
How to build your own blog website by yourself
Practical application of information security
Yunna | how to use the system to manage fixed assets? How to manage fixed assets?
出门在外保护好自己
Outsourcing for 3 years is a waste
Analysis of IM instant messaging development technology on modern web
A Yu's Rainbow Bridge
利用huggingface进行文本分类
RubyMine开发工具,重构和意图操作
DL:深度学习模型优化之模型训练技巧总结之适时自动调整学习率实现代码
After the element uses align items center and overflow auto, some contents are not fully displayed
2022 6 月25 日交易总结
我,33岁,字节跳动测试开发,揭开北京“测试岗”的真实收入
The listing of Symantec electronic sprint technology innovation board: it plans to raise 623million yuan, with a total of 64 patent applications
Arlo felt lost
Visual Studio 2017 无法打开包括文件: “QOpenGLFunctions_3_3_Core”: No such file or directory
How to design test cases
Solving plane stress problem with MATLAB
【Spark】scala基础操作(持续更新)