c primer plus 3.11
1、
#include <stdio.h> #include <float.h> #include <limits.h> int main(void) { int big_int = 2147483647; float big_float = 3.4E38; float small_float = 10.0/3; printf("The big int data is %d\n", big_int + 1); printf("The big float data is %f\n", big_float * 10); printf("The big float data is %f\n", small_float); printf("The MAX float data is %f\n", FLT_MAX); printf("The max int data is %ld\n", INT_MAX); return 0; }
3.11-2
#include <stdio.h> int main(void) { int ch; printf("please input an number for char type: "); scanf("%d", &ch); printf("%d is equivalent to %c.\n", ch, ch); return 0; }
3.11-3
#include <stdio.h> int main(void) { char alarm = '\a'; printf("%c", alarm); printf("xxxxxxx.\n"); printf("\"yyyyyyyyy\".\n"); return 0; }
3.11-4
#include <stdio.h> int main(void) { float test; printf("please input an float value: "); scanf("%f", &test); printf("fixed-point notation: %f.\n", test); printf("exponential notation: %e.\n", test); printf("p notation: %a.\n", test); return 0; }
3.11-5
#include <stdio.h> #define SEC_PER_YEAR 3.156e7 int main(void) { float age, second; printf("please input your age: "); scanf("%f", &age); second = SEC_PER_YEAR * age; printf("your age is %.2f.\n", age); printf("your age is equivalent to %e seconds.\n", second); return 0; }
3.11-6
#include <stdio.h> #define GRM_PER_MOLE 3.0e-23 #define GRM_PER_QUART 950 int main(void) { float guart, gram, molecular; printf("please input the quarts: "); scanf("%f", &guart); gram = guart * GRM_PER_QUART; molecular = gram / GRM_PER_MOLE; printf("the number of water molecular: %e.\n", molecular); return 0; }
3.11-7
#include <stdio.h> #define CENTIMETER_PER_INCH 2.54 int main(void) { float height_inch, height_centimeter; printf("please input your height in inch: "); scanf("%f", &height_inch); height_centimeter = height_inch * CENTIMETER_PER_INCH; printf("your height in centimeter is: %.1f.\n", height_centimeter); return 0; }
3.11-8
#include <stdio.h> int main(void) { float cups; printf("please input cups: "); scanf("%f", &cups); printf("pint: %.1f\n", cups/2); printf("ounce: %.1f\n", cups * 8); printf("big spoon: %.1f\n", cups * 8 * 2); printf("tea spoon: %.1f\n", cups * 8 * 2 * 3); return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律