数据类型 | 结构体
摘要:结构是一种复合的数据类型,可以包含多个不同类型的成员变量。
我们可以通过结构类型声明结构,并通过结构变量来访问结构的成员。结构变量可以赋初值,可以进行运算,还可以作为函数参数传递。
阅读全文
posted @
2023-12-03 16:49
Mryan2005
阅读(115)
推荐(0) 编辑
PTA | 7-9 螺旋方阵
摘要:题目 所谓“螺旋方阵”,是指对任意给定的N,将1到N×N的数字从左上角第1个格子开始,按顺时针螺旋方向顺序填入N×N的方阵里。本题要求构造这样的螺旋方阵。 输入格式: 输入在一行中给出一个正整数N(<10)。 输出格式: 输出N×N的螺旋方阵。每行N个数字,每个数字占3位。 输入样例: 5 输出样例
阅读全文
posted @
2023-11-30 22:45
Mryan2005
阅读(115)
推荐(0) 编辑
【关于PTA平台中出现的问题】warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
摘要:今天,我在PTA里面刷题的时候,碰到了这样的情况 warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result 其实,当时,我写了这样的代码 #include <stdio.h> int m
阅读全文
posted @
2023-11-30 11:38
Mryan2005
阅读(443)
推荐(0) 编辑
多重循环
摘要:如何输出100以内的素数 之前,我们写出了判断这个数值是不是素数的代码 #include <stdio.h> int main () { int num, isPrime; scanf("%d",&num); for (int i = 2; i <= num/2; i++) { if(num % i
阅读全文
posted @
2023-11-20 07:45
Mryan2005
阅读(6)
推荐(0) 编辑
循环应用
摘要:求最大公约数 基本原理 举个例子吧 例如:我们要算12和18的公约数。 其实,只要先12%18就可以得到一个余数,然后再拿这个余数%18,然后得到一个余数,最后将这个余数除以12,直至b = 0 如下所示 a b mod 12 18 12 18 12 6 12 6 0 6 0 代码实现 #inclu
阅读全文
posted @
2023-11-20 07:45
Mryan2005
阅读(4)
推荐(0) 编辑
第四章 变量
摘要:如果声明一个变量,它会在内存划定一个区域,并将其数值存下 变量的定义 做法:(变量类型)(变量标识符) 例如: int number = 0; 先在定义变量,再使用,并且对于非全局变量来说,一个函数内只能定义一次。 例如: #include <stdio.h> int main(){ int pri
阅读全文
posted @
2023-11-20 07:45
Mryan2005
阅读(7)
推荐(0) 编辑
第五章 数据类型
摘要:类型与描述 基本数据类型:int、char(字符型)、float、double、bool类(class)数组型:[]空类型:void结构数据类型结构体型(struct)联合体型(union)枚举类型(enum)指针型(*) sizeof()函数的妙用 当你不知道一个数据类型或数组占用多少个字节时,s
阅读全文
posted @
2023-11-20 07:45
Mryan2005
阅读(6)
推荐(0) 编辑
数据类型 | 常量
摘要:定义 在程序运行过程中,其值保持不变的量。 字面常量 如-1,0,123,4.6…… 符号常量 用一个标识符代表的一个常量的数 在变量类型前面加一个const 例如 const int id; 类型 10000L // 长整型常量 10000U // 无符号整型常量 3.141F // 双精度浮点型
阅读全文
posted @
2023-11-20 07:45
Mryan2005
阅读(54)
推荐(0) 编辑
循环语句 | 循环运算
摘要:求一个以二为底的对数 毕竟它是循环/2,所以我们可以这样写。 #include <stdio.h> int main() { int x, rate = 0; scanf("%d", &x); int t = x; // 我们要保存一下x的原始值 while (x>1) { x /= 2; rate
阅读全文
posted @
2023-11-16 07:45
Mryan2005
阅读(6)
推荐(0) 编辑
循环语句 | 循环控制
摘要:主要是break;和continue; 怎样才能打破循环? 用break; #include <stdio.h> int main () { int num; scanf("%d",&num); int i = 0; if (num > 0){ while ( num > 0 ){ num /= 1
阅读全文
posted @
2023-11-16 07:45
Mryan2005
阅读(11)
推荐(0) 编辑
C语言中的Fibonacci数
摘要:什么是Fibonacci数 斐波那契数列(Fibonacci sequence),又称黄金分割数列,因数学家莱昂纳多·斐波那契(Leonardo Fibonacci)以兔子繁殖为例子而引入,故又称“兔子数列”,其数值为:1、1、2、3、5、8、13、21、34……在数学上,这一数列以如下递推的方法定
阅读全文
posted @
2023-11-14 12:23
Mryan2005
阅读(112)
推荐(0) 编辑
第三章 三大结构 | 循环语句
摘要:while 函数 可以这样理解,当满足什么条件时,执行while循环。 编写格式 while (condition) { // this is the function } 当满足condition时,循环可以运行。 如果condition内的东西不变,那么就会造成一个死循环。 do-while循环
阅读全文
posted @
2023-11-11 19:43
Mryan2005
阅读(9)
推荐(0) 编辑
第三章 三大结构 | 分支结构
摘要:if语句 语句结构 if (condition1 || condition2) { // input the function } else if (condition3 && condition4){ // input the function } else { // input the func
阅读全文
posted @
2023-11-11 19:43
Mryan2005
阅读(6)
推荐(0) 编辑
第二章 输入与输出(下)——getchar函数和putchar函数
摘要:getchar() 函数和putchar() 函数只能处理单个字符。 getchar() 函数 基本格式:c = getchar() 它可以忽略掉空格,回车之类的东西,但是它是只收入字符。 #include <stdio.h> int main () { char c; do { printf("请
阅读全文
posted @
2023-11-10 07:45
Mryan2005
阅读(34)
推荐(0) 编辑
第三章 三大结构 | 顺序语句
摘要:顺序语句就是从左到右依次完成 由图,我们可以知道——程序从开始到结束只有一条路径。 用代码表示就是 #include <stdio.h> int main() { char a; scanf("%c",&a); printf("%c",a); return 0; }
阅读全文
posted @
2023-11-10 07:45
Mryan2005
阅读(5)
推荐(0) 编辑
第二章 输入与输出(上)——scanf()函数和printf()函数
摘要:就是scanf()函数、printf()函数、getchar()函数和putchar()函数,它们都要引入stdio.h printf()函数 日常使用 # include <stdio.h> void main { printf("hello world!"); } 结果就是hello world
阅读全文
posted @
2023-11-09 13:24
Mryan2005
阅读(11)
推荐(0) 编辑
第一章 与君初相识
摘要:它的基本结构 一句话总结 C语言的源代码由预处理指令、函数、变量、语句&不等式、注释构成 如下所示 # include <stdio.h> // 预处理指令 int main(){ //函数 int text; text = 24; //变量 printf("hello world!\n"); //
阅读全文
posted @
2023-11-09 12:18
Mryan2005
阅读(7)
推荐(0) 编辑