- 最大公约数:
{1}思路:a与b的最大公约数=a除以b的余数c和较小数b的最大公约数
{2}
#include <stdio.h>int f(int a, int b){ int c; c = a%b; if (c == 0) { return b; } else { return f(b, c); }}int main(){ int a, b; scanf("%d %d", &a, &b); printf("%d", f(a, b)); return 0;}
2.全局变量VS局部变量(练习)
3.time.h
time()函数,获取当前时间戳
示例:time(NULL)
返回从协调世界时1970年1月1日00:00:00(UNIX纪元)到当前时刻的毫秒(1000毫秒)数
4. stdlib.h 随机数函数
Xn+1 = aXn + b mod m
在前一个随机数的基础上,通过一系列的计算得到下一个。
srand(种子)
rand()
获取随机数 int num = rand(); printf("%d", num);