#include "stdio.h"int main()
{
int n,m,kase = 0;
while(scanf("%d%d",&n,&m) != EOF && n && m)
{
doublesum = 0;
for(int x = n; x <= m; x++)
{
double y = 1.0 / x;
y *= y;
sum += y;
}
printf("Case %d: %.5lf\n",++kase,sum);
}
getchar();getchar();
return0;
}
Exercise2-5 decimal
#include "stdio.h"int main()
{
int a, b, c, kase = 0;
while(scanf("%d%d%d",&a,&b,&c) != EOF && a && b && c)
{
printf("Case %d: %d.",++kase, a / b);
a -= (a/b)*b;
for(int i = 1; i <= c; i++)
{
a *=10;
printf("%d", a / b);
a -= (a/b)*b;
}
printf("\n");
}
getchar();getchar();
return0;
}
Exercise2-6 permutation
#include "stdio.h"#include "string.h"int main()
{
int num[10];
for(intx = 102; x <= 329; x++)
{
int sum = 0;
memset(num, 0, sizeof(num));
inty = x;
for(int i = 1; i <= 3; i++,y += x)
{
num[y / 100] = 1;
num[y % 100 / 10] = 1;
num[y % 10] = 1;
}
for(int i = 0; i <= 9; i++)
sum += num[i];
if(sum == 9)
printf("%d%d%d\n",x,2*x,3*x);
}
getchar();getchar();
return0;
}