摘要: c语言中输出不同数据类型在内存中的占位 1、 #include <stdio.h> int main(void) { int n = 0; unsigned x = ~0U; while(x) { if(x & 1U) n++; x >>= 1; } printf("the number of bi 阅读全文
posted @ 2021-05-20 23:05 小鲨鱼2018 阅读(274) 评论(0) 推荐(0) 编辑
摘要: c语言中输出十进制数转换为二进制数后包含1的数目 1、 #include <stdio.h> int main(void) { unsigned a; puts("please input a nonnegative integers."); printf("a = "); scanf("%u", 阅读全文
posted @ 2021-05-20 22:54 小鲨鱼2018 阅读(196) 评论(0) 推荐(0) 编辑
摘要: c语言中sizeof运算符,输出不同数据类型的长度 1、 a、sizeof运算符的符号是字节 b、各种数据类型的有符号型和无符号型长度一致 c、一般情况 short <= int <= long。 #include <stdio.h> int main(void) { puts("show the 阅读全文
posted @ 2021-05-20 21:18 小鲨鱼2018 阅读(587) 评论(0) 推荐(0) 编辑
摘要: c语言中的位以及不同的数据类型可以表示的数值的范围。 1、计算机中的所有数据类型都是用0和1的组合来表示的,这个0和1的占位就是位。 位是具有大量内存空间的运行环境的数据存储单元,可保存具有两种取值的对象。 不同数据类型在内存上的占位决定了其可以表示数值的范围。 比如无符号整型在内存上的占位为n,那 阅读全文
posted @ 2021-05-20 21:07 小鲨鱼2018 阅读(587) 评论(0) 推荐(0) 编辑
摘要: c语言中在编译器中判断char属于signed char 还是 unsigned char。 1、 判断CHAR_MIN非0,则输出“signed”, 如果为0,则输出“unsigned”,因为unsigned型的最小值为0. #include <stdio.h> #include <limits. 阅读全文
posted @ 2021-05-20 20:57 小鲨鱼2018 阅读(205) 评论(0) 推荐(0) 编辑
摘要: c语言中输出整型和字符型9中数据类型在编译器中可以表示的数值范围。 1、 a、无符号整型的显示使用 %u b、long型数据的显示使用 %l c、无符号整型的最小值为0. #include <stdio.h> #include <limits.h> int main(void) { printf(" 阅读全文
posted @ 2021-05-20 20:50 小鲨鱼2018 阅读(476) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> int main(void) { float x1, sum1 = 0.0; for(x1 = 0.0; x1 <= 1.0; x1 += 0.01) { sum1 += x1; } int i; float sum2 = 0.0; for(i = 1; 阅读全文
posted @ 2021-05-20 19:04 小鲨鱼2018 阅读(40) 评论(0) 推荐(0) 编辑
摘要: 1、 利用浮点进行循环的时候,计算机不能保证计算机内部转换为二进制后不发生数据丢失,因此随着循环的进行,会发生误差的积累。 #include <stdio.h> int main(void) { int i; float x1 = - 0.01, x2; for(i = 0; i <= 100; i 阅读全文
posted @ 2021-05-20 18:37 小鲨鱼2018 阅读(70) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> #include <math.h> int main(void) { double x; puts("please input an double value."); printf("x = "); scanf("%lf", &x); printf("re 阅读全文
posted @ 2021-05-20 18:07 小鲨鱼2018 阅读(91) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> int main(void) { float x1, sum1 = 0.0; for(x1 = 0.0; x1 <= 1.0; x1 += 0.01) { sum1 += x1; } int i; float x2, sum2 = 0.0; for(i = 阅读全文
posted @ 2021-05-20 15:54 小鲨鱼2018 阅读(51) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> int main(void) { float x1 = -0.01; int x2 = 0; int i; float sum1 = 0.0 , sum2 = 0.0; for(i = 0; i <= 100; i++) { x1 += 0.01; sum 阅读全文
posted @ 2021-05-20 13:03 小鲨鱼2018 阅读(51) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> int main(void) { float x1 = -0.01; int x2 = 0; int i; for(i = 0; i <= 100; i++) { printf("x = %f x = %f\n", x1 += 0.01, x2++ / 1 阅读全文
posted @ 2021-05-20 12:55 小鲨鱼2018 阅读(42) 评论(0) 推荐(0) 编辑
摘要: 创建一个程序,输入一个实数作为面积,求面积为该实数的正方形的边长。 #include <stdio.h> #include <math.h> int main(void) { double area; puts("please input the area."); printf("area = ") 阅读全文
posted @ 2021-05-20 11:25 小鲨鱼2018 阅读(58) 评论(0) 推荐(0) 编辑
摘要: 1、创建一个程序,使用sizeof运算符显示3种浮点型的长度。 3种浮点型: float; double; long double; #include <stdio.h> int main(void) { printf("sizeof(float) = %d\n", sizeof(float)); 阅读全文
posted @ 2021-05-20 11:07 小鲨鱼2018 阅读(110) 评论(0) 推荐(0) 编辑
摘要: c语言中<math.h>头文件,计算两点之间的距离。 <math.h>头文件包含基本数学函数的函数原型声明。 1、 #include <stdio.h> #include <math.h> double dist(double x1, double y1, double x2, double y2) 阅读全文
posted @ 2021-05-20 10:39 小鲨鱼2018 阅读(683) 评论(0) 推荐(0) 编辑