编程笔记
-
读取string,float和int值
#include <stdio.h> #include <string.h> // for strlen() prototype #define DENSITY 62.4 // human density in lbs per cu ft int main() { float weight, volume; int size, letters; char name[40]…
-
读取一定量的水,以夸脱为单位,并显示该数量的水分子数。
单分子水的质量约为3.0×10克。一夸脱水约950克。 #include <stdio.h> int main(void) { float mass_mol = 3.0e-23; /* mass of water molecule in grams */ float mass_qt = 950; /* mass of quart of water …
-
浮点舍入错误
取一个数字,加1,然后减去原始数字。浮点计算可能会给出另一个答案: #include <stdio.h> int main(void) { float a,b; b = 2.0e20 + 1.0; a = b - 2.0e20; printf("%f /n", a); return 0; }
-
生成未来值利息因素表(VIF)
#include <stdio.h> #include <math.h> #define MAX_INTEREST 6 #define MAX_PERIOD 10 int main() { int interest; float fvif; printf("/nRate of interest varies from 1% to 6%."); prin…
-
使用蒙特卡罗方法计算Pi的数学常数值
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int p, intCircle = 0, intSquare, intToss = 3000, intRM; float pi, x, fltY, fltR; intRM = RAND_MAX; intSquare = …
-
使用无限级数展开计算角度x的正弦值
这里给出了无限级数展开的公式: sin x = x - x3/3! + x5/5! - x7/7! + ... 这里,x是弧度,它取值范围-1 <= x <= 1。 #include <stdio.h> int main() { double sine, term, x = 0.7, z; int k = 1; ch…
-
使用无限级数展开计算角度x的余弦函数
这里给出了无限级数展开的公式: cos x = 1 - x2/2! + x4/4! - x6/6! +... 这里,x是弧度,它取值范围-1 <= x <= 1。 #include <stdio.h> int main(){ double cosine, x = 0.7, z; int j, q, flag, fac…
-
计算二次方程的根
计算二次方程ax ^ 2 + bx + c = 0的根。 由以下公式给出: (-b + square_root(b2 - 4ac))/2a 和 (-b - square_root(b2 - 4ac))/2a 参考以下代码: #include <stdio.h> #include <math.h> int main(){ d…
-
除以两个给定的整数,显示结果为3位小数
#include <stdio.h> int main (void) { int i1, i2; printf ("Enter two numbers: "); scanf ("%i%i", &i1, &i2); if (i2 == 0) printf ("the second number cannot be zer…
-
求解:多项式的求值
#include<stdio.h> int main (void) { float result; float x = 2.55; result = 3 * x * x * x + 5 * x * x + 6; printf("result = %f/n", result); return 0; }