- 博客(13)
- 收藏
- 关注
原创 scanf输入char型数据时被回车或空格占用
scanf函数和gets()函数在使用时一定要慎重。#include<stdio.h>int main(){ char n,m; scanf("%c",&n); scanf("%c",&m); printf("%c %c",n,m);}运行结果当输入第一个字符a的时候,后面的空格就会自动进入第二个scanf函数中,这个时候就需要进行缓冲区刷新`#include<stdio.h>int main(){ char n,m; scanf("%
2021-10-24 14:45:11
1312
原创 回文串 C语言
#include<stdio.h>#include<cstring>const int maxn=256;bool judge(char str[]){ int len = strlen(str); int i=0; if(len%2 == 0){ for(; i<=(len/2); ) { if(str[i] == str[len-i-1]){ i++; } else{ return false; }
2021-10-17 14:28:56
460
原创 C语言 四舍五入
#includeint main(){\n为被除数,m为除数double n, m;scanf("%lf %lf",&n,&m);int k;if((n/m)>=((((int)(n)/(int)m)+0.5))){k=(int)(n)/(int)m+1;}else{k=(int)(n)/(int)m;}printf("%d",k);return 0;}
2021-10-11 19:19:56
463
原创 c语言从定义函数返回一个一维数组到main()函数
#include <stdio.h>/*int * Function(){ ``` 从函数返回一个一维数组, 定义的函数也应该为返回指针的函数。 ```}*/ int * getFunction(){ static int a[5]; /* C语言不支持在函数外返回局部变量的地址,除非定义为static变量。 */ int i = 0; for( ; i<5; ) { a[i] = i; i++; } return a;
2021-06-25 20:39:20
538
原创 c语言的定义常量
#include<stdio.h>/*定义常量①使用 define 预处理器 #define + 变量名 + value ②使用 const 关键字 const + 数据类型 +变量名 = 数据 */#define hours 24int main(){ const int days = 30 ; int allHours ; allHours = days * hours ; printf("allhours: %d",allHours); return 0;
2021-06-18 20:20:31
442
原创 c语言中头文件和return 0的意思
#include <studio.h>调用printf()函数需要此头文件int main(){return 0return 0 对应的是int main()也表示结束这一段程序}
2021-06-13 18:17:12
632
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人