编程笔记
-
使用strtol()将字符串值转换为long类型值
#include <stdio.h> #include <stdlib.h> #define LIM 30 char * s_gets(char * st, int n); int main(){ char number[LIM]; char * end; long value; puts("Enter a number (empty line to quit)…
-
计算木星和太阳之间的光年
#include <stdio.h> int main() { float lightyear=5.878E12; float jupiter=483400000; float distance; distance=jupiter/lightyear; printf("Jupiter is %f light years from the sun./n",dista…
-
读取类型双精度数字并打印数字立方的值
#include <stdio.h> double cubed(double n); // prototype declaration for cubed int main(void){ double input; printf("Enter a number to cube: "); scanf("%lf", &input); pri…
-
将鞋码转换为英寸
#include <stdio.h> #define ADJUST 7.31 // one kind of symbolic constant int main(void){ const double SCALE = 0.333; // another kind of symbolic constant double shoe, foot; shoe = 9.0; foot = SC…
-
使用while循环计算多种尺寸的英尺长度
#include <stdio.h> #define ADJUST 7.31 // one kind of symbolic constant int main(void){ const double SCALE = 0.333; // another kind of symbolic constant double shoe, foot; shoe = 3.0; while (sh…
-
将类型double变量设置为1.0/3.0,将float类型设置为1.0/3.0
显示每个结果三次: 显示小数点右边的4位数, 显示小数点右边的12位数字, 显示小数点右侧的16位数字。 包括float.h并显示FLT_DIG和DBL_DIG。 #include <stdio.h> #include <float.h> int main(void) {…
-
读取浮点数并以十进制表示法,指数表示法和p表示法打印
#include <stdio.h> int main(void) { float flt_input; printf("Enter a floating-point value: "); scanf("%f", &flt_input); printf("Fixed-point notation: %f/n", fl…
-
读取浮点数并首先以小数点表示法打印,然后以指数表示法打印
输出使用以下格式: 输入为21.3或2.1e + 001。 输入为+21.290或2.129E + 001。 #include <stdio.h> int main(void) { float num; printf("Enter a number: "); scanf("%f", &num); p…
-
读取两个浮点数并打印它们的差值除以乘积的值
#include <stdio.h> int main( void ) { double n, m; double res; printf("Enter a pair of numbers: "); while (scanf("%lf %lf", &n, &m) == 2) { res = (n - m) / (n * m); …
-
使用来自float.h和limits的数据,找到该系统的一些数字限制
#include <stdio.h> #include <limits.h> // integer limits #include <float.h> // floating-point limits int main(void){ printf("Biggest int: %d/n", INT_MAX); printf("Sma…