题目描述:
1、找出1到100里,9出现的次数。
2、计算1/1-1/2+1/3……+1/33-1/100。
由于题目过于简单,直接上代码
题目一代码:
int main()
{
int a = 1;
int b = 100;
int num = 0;
int c = 0;
for (a = 2; a < 100; a++)
{
if (a < 10 && a % 9 == 0)
num += 1;
if (a < 90 && a >= 10)
{
c =( a - (a / 10) * 10 );
if (c % 9 == 0&&c!=0)
num += 1;
}
if (a >= 90 && a < 99)
{
num += 1;
}
if (a == 99)
num += 2;
}
printf("%d\n", num);
return 0;
题目2代码:
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <math.h>
int main()
{
float a = 0.0;
float b = 0.0;
float c = 0.0;
int loop = 0;
for (loop = 1; loop <= 100; loop+=2)
{
a = a + 1.0 / loop;
b = b - 1.0 / (loop + 1);
}
c = a + b;
printf("%lf\n", c);
return 0;