摘要:
给数组中每个元素赋相同的值 memset(数组名,值,sizeof(数组名)); #include<stdio.h> #include<string.h> int main(){ int a[5]={1,2,3,4,5}; memset(a,0, sizeof(a)); for(int i=0;i< 阅读全文
posted @ 2019-12-16 23:45
老葛
阅读(247)
评论(0)
推荐(0)
摘要:
#include<stdio.h> int main(){ int a[10]={5,4,3,2,1}; for(int i=1;i<=4;i++){ for(int j=0;j<5-i;j++){ //每走一轮就能把最大的数放到最后,所以每一趟比较次数递减 if(a[j]>a[j+1]){ int 阅读全文
posted @ 2019-12-16 23:03
老葛
阅读(76)
评论(0)
推荐(0)
摘要:
fabs()绝对值函数 #include<stdio.h> #include<math.h> int main(){ double db=-12.56; printf("%.2f\n", fabs(db)); return 0; } floor()向下取整;ciel()向上取整 不管四舍五入,向上取 阅读全文
posted @ 2019-12-16 20:16
老葛
阅读(630)
评论(0)
推荐(0)
摘要:
其实在这里困扰了很久,因为数据结构书上用了很多类似的定义,一度十分不想打开数据结构。 其实就是给某个类型取一个更好记的别名,然后用这个别名去代替这个类型。 实例如下: #include<iostream> #include<stdio.h> using namespace std; typedef 阅读全文
posted @ 2019-12-16 19:39
老葛
阅读(236)
评论(0)
推荐(0)
摘要:
getchar()和putchar()只能用于输入输出单个字符,而不能字符串。 #include<iostream> using namespace std; int main(){ char c1,c2; c1=getchar(); c2=getchar(); putchar(c1); putch 阅读全文
posted @ 2019-12-16 19:29
老葛
阅读(1418)
评论(0)
推荐(0)
摘要:
两数相加,结果每三位添加一个逗号。一开始没有注意到%03d的问题,因为有某些数据逗号分割后高位带0,因此需要用0来补充空位。 1 #include<iostream> 2 #include<stdio.h> 3 using namespace std; 4 int main(){ 5 int a,b 阅读全文
posted @ 2019-12-16 18:53
老葛
阅读(207)
评论(0)
推荐(0)

浙公网安备 33010602011771号