- 博客(20)
- 收藏
- 关注
原创 用函数判断是否为闰年
#include <stdio.h>#include <string.h>int is_leap_year(int y){ if((y%4==0&&y%100!=0) || (y%400==0) ) return 1; else return 0;}int main(){ int year = 0; for(year=1000; year<=2000; year++) { //判断year是否为闰年 .
2022-04-23 18:49:25
356
原创 写一个函数比较大小
#include <stdio.h>#include <string.h>//定义函数int get_max(int x, int y) { if(x>y) return x; else return y; }int main(){ int a = 10; int b = 20; //函数的使用 int max = get_max(a,b); printf("max = %d\n", max); } ...
2022-04-23 17:14:34
319
原创 猜数字游戏
#include <stdio.h>#include <string.h>void menu(){ printf("***************************\n"); printf("**** 1.play 0.exit ****\n"); printf("***************************\n");}void game(){ printf("猜数字\n");}int main(){ int input = 0.
2022-04-22 09:41:37
3045
原创 打印九九乘法表
#include <stdio.h>#include <string.h>int main(){ int i = 0; //确定打印九行 for(i=1; i<=9; i++) { //打印一行 int j = 1; for(j=1; j<=i; j++) { printf("%d*%d=%-2d", i ,j, i*j); } printf("\n"); } return 0; }...
2022-03-31 19:28:14
266
原创 数组中寻找最大数
#include <stdio.h>#include <string.h>int main(){ int arr[] = {1,2,3,4,5,6,7,8,9,10}; int max = arr[0]; //比如放第一个元素 int i = 0; int sz = sizeof(arr)/sizeof(arr[0]); //求元素个数 for(i=1; i<sz; i++) { if(arr[i] > max) { max = arr[.
2022-03-30 19:57:53
129
原创 1~100 分数求和
#include <stdio.h>#include <string.h>int main(){ int i = 0; double sum = 0; int flag = 1; for(i=1; i<=100; i++) { sum += flag*1.0/i; flag = -flag; } printf("%lf\n" ,sum); return 0; }
2022-03-30 19:38:13
591
原创 1~200判断是否为素数
#include <stdio.h>#include <string.h>int main(){ int i = 0; int count = 0; for(i=100; i<=200; i++) { // 判断i是否为素数 // 试除法 // 产生 2 -> i-1 int j = 0; for(j=2; j<i; j++) { if(i%j==0) { break; } } .
2022-03-30 19:03:06
137
原创 统计有多少个闰年
法一include <stdio.h>#include <string.h>int main(){ int year = 0; int count = 0; for(year=1000; year<=2000; year++) { //判断year是否为闰年 //1. 能被4整除并且不能被100整除是闰年 //2. 能被400整除是闰年 if(year%4==0 && year%100!=0) { pr
2022-03-29 21:28:19
457
原创 给定两个数,求这两个数的最大公约数
#include <stdio.h>#include <string.h>int main(){ int m = 0; int n = 0; int r = 0; scanf("%d%d", &m, &n); while(m%n) { r = m%n; m = n; n = r; } printf("%d\n", n);}
2022-03-29 20:44:32
310
原创 1~100打印3的倍数
#include <stdio.h>#include <string.h>int main(){ int i = 0; for(i=1; i<=100; i++) { if(i%3 == 0) printf("%d ",i); }}
2022-03-29 20:30:27
115
原创 打印三个数从大到小排序
#include <stdio.h>#include <string.h>int main(){ int a = 0; int b = 0; int c = 0; scanf("%d%d%d", &a, &b, &c); //a b c 从大到小排序 if(a<b) { int tmp = a; a = b; b = tmp; } if(a<c) { int tmp = a; a = c.
2022-03-29 20:25:06
144
原创 输入密码登录
#include <stdio.h>#include <string.h>int main(){ int i = 0; char password[20] = {0}; for(i=0; i<3; i++) { printf("请输入密码:>"); scanf("%s", password); if(strcmp(password, "123456") == 0) // ==不能用来比较两个字符串是否相等,应该使用一个库函数-strcmp.
2022-03-28 20:24:14
506
原创 n的阶乘累加
#include <stdio.h>int main(){ int a = 0; int b = 0; int ret = 1; int sum = 0; for(b=1; b<=10; b++) { ret = 1; //防止累加 for(a=1; a<=b; a++) { ret = ret * a; } sum = sum + ret; } printf("sum = %d\n", sum); re.
2022-03-28 19:19:14
435
原创 for循坏循环次数 I like you
嵌套循环打印100次 I like you#include <stdio.h>int main(){ int i = 0; for(i=0; i<10; i++) { int j = 0; for(j=0; j<10; j++) { printf("I like you\n"); } } //10*10=100 return 0; } 如果贸然沈略会导致打印出错#include <stdio.h>i.
2022-03-27 21:29:33
470
原创 while循环2
输入密码#include <stdio.h>int main(){ int ret = 0; int ch = 0; char password[20] = {0}; printf("请输入密码:>"); scanf("%s",password); //输入密码,并存放password数组中 //缓冲区还剩余一个'\n' //读取一下'\n' while(ch=getchar() !='\n') { ; } printf("请确认(Y/N):>"
2022-03-26 21:36:54
691
原创 while循环1
#include <stdio.h>int main(){ if(1) printf("yyds\n"); return 0; }
2022-03-26 20:18:42
376
原创 Switch 语句 打印星期
#include <stdio.h>int main(){int day = 0;scanf("%d", &day);switch(day){case 1:printf(“星期一\n”);case 2:printf(“星期二\n”);case 3:printf(“星期三\n”);case 4:printf(“星期四\n”);case 5:printf(“星期五\n”);case 6:printf(“星期六\n”);case 7:printf(“星期
2022-03-25 17:24:18
479
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅