1.计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值。

#include <stdio.h>
#include <stdlib.h>
int main() {
	double x = 0.0,y = 0.0;
	for (int i = 1; i <= 100; i += 1) {
		y = 1.0 / i;
		if (i % 2 != 0) {
			x += y;
		}
		else {
			x -= y;
		}
	}
	printf("%lf\n", x);
	system("pause");
	return 0;
}

2.编写程序数一下 1到 100 的所有整数中出现多少次数字9。

#include <stdio.h>
#include <stdlib.h>
int main() {
	int time = 0;
	int arr[100] = { 0 };
	for (int i = 1; i <= 100; i += 1) {
		arr[i-1] = i;
		if (arr[i-1] == 99) {
		time += 2;
		}
		else if (arr[i-1] % 10 == 9) {
			time += 1;
		}
		
		else if ((arr[i-1] % 100) - (arr[i-1] % 10) == 90) {
			time += 1;
		}
		else time += 0;
	}
	printf("%d\n", time);
	system("pause");
	return 0;
}