一、例题
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; }