第2章(第四版)C语言程序设计练习
作者:互联网
一、例题
1.求5!(P33)
#include <stdio.h> int main() { int i = 0; int ret = 1; for (i = 1; i <= 5; i++) { ret *= i; } printf("ret =%d\n", ret); return 0; }
2.求多项式1- 1⁄2 + 1⁄3 -1⁄4 +...+1⁄99 - 1⁄100 (P33)
#include<stdio.h> int main() { double sum = 0; double n = 0; int sign = -1; for (n = 1; n <= 100; n++) { sign = -sign; sum = sum + sign / n; } printf("%f", sum);//0.688172 return 0; }
标签:include,int,double,例题,C语言,第四版,P33,程序设计,main 来源: https://www.cnblogs.com/mljrm/p/15541573.html