摘要: 一、引入 质数(素数):只能被1和本身整除的数,0和1既不是质数也不是合数 实际上是求素数的一种算法 二、代码 #include <stdio.h> #define N 100 void main(){ int i,array[N],j; //0和1既不是质数也不是合数 array[0]=0; ar 阅读全文
posted @ 2019-12-25 11:07 小菜将夜 阅读(265) 评论(0) 推荐(0)
摘要: 一、代码 #include <stdio.h> #include <stdlib.h> void main(){ int x,*array; printf("需要申请的数组大小:"); scanf("%d",&x); array=malloc(x*sizeof(int)); for(int i=0; 阅读全文
posted @ 2019-12-25 10:10 小菜将夜 阅读(193) 评论(0) 推荐(0)
摘要: 一、代码 ①struct #include <stdio.h> struct Point{ int x; int y; }; void main(){ struct Point point; point.x=1; point.y=2; printf("x:%d,y:%d",point.x,point 阅读全文
posted @ 2019-12-25 09:39 小菜将夜 阅读(83) 评论(0) 推荐(0)
摘要: 一、代码 main.c文件 #include <stdio.h> #include "myH.h" void main(){ printf("%d",getInt()); } myH.h文件 #ifndef _SOMEFILE_H_ //如果_SOMEFILE_H_没有被定义 #define _SO 阅读全文
posted @ 2019-12-24 17:46 小菜将夜 阅读(737) 评论(0) 推荐(0)
摘要: 一、代码 #include <stdio.h> typedef int myInt; void main(){ myInt x=1; printf("%d",x); } 结果: 总结:typedef并不是创建新的类型,而是重命名而已 阅读全文
posted @ 2019-12-24 17:22 小菜将夜 阅读(111) 评论(0) 推荐(0)
摘要: 一、代码 #include <stdio.h> void main(){ printf("%d",get()); } int get(){ return 1; } 结果: 总结:不需要额外的声明,只要定义好函数和方法体就行,也没有额外的顺序限制,与java类似 阅读全文
posted @ 2019-12-24 17:17 小菜将夜 阅读(227) 评论(0) 推荐(0)
摘要: 一、问题引出 现在有多个尚未连通的城市A、B、C...,现在政府要在每个城市修建高速公路,使每个城市都连通起来。但是呢,由于今年的财政收入赤字,没有过多的预算,所以决定在每连通两个城市的时候判断一下,这两城市到底是不是互通的,以此来节省费用。比如:已经修建了A-B、B-C之间的道路,那么在判断A-C 阅读全文
posted @ 2019-12-24 16:46 小菜将夜 阅读(649) 评论(0) 推荐(0)
摘要: 一、线程的编写方式 ①继承Thread类 ②实现Runnable接口(推荐使用,JAVA是单继承,如果该类已经继承了一个类了,那么就只能使用实现接口的方式) class MyThread extends Thread{ @Override public void run() { System.out 阅读全文
posted @ 2019-12-06 17:35 小菜将夜 阅读(896) 评论(0) 推荐(0)
摘要: 在多线程学习的开始,首先要了解几个重要的概念 一、线程和进程 进程:是操作系统进行资源分配和调度的独立单位 线程:是进程中独立运行的子任务 一个进程可能包含多个线程 二、随机 即使启动线程的代码有先后顺序,实际上线程的启动和调用是随机的,cpu时间片一直在切换 三、线程安全和非线程安全 在多线程下, 阅读全文
posted @ 2019-12-05 11:03 小菜将夜 阅读(196) 评论(0) 推荐(0)