第一题:
#include<stdio.h>
main()
{
int a,b,mul,thousand,hundred,ten;
printf("Enter a and b:\n");
scanf("%d %d",&a,&b);
mul=a*b;
thousand=mul/1000;
mul-=thousand*1000;
hundred=mul/100;
mul-=hundred*100;
ten=mul/10;
mul-=ten*10;
printf("%d与%d的乘积为:%d\n",a,b,a*b);
printf("百位:%d\n",hundred);
printf("十位:%d\n",ten);
printf("个位:%d\n",mul);
}
第二题:
#include<stdio.h>
#define count 20
main()
{
int i,j;
float k,total=0,sum=1;
for(i=1;i<=count;i++)
{
for(j=i;j>0;j--)
{
sum*=j;
k=1/sum;
}
total+=k;
}
printf("total=%f\n",total);
}
[
本帖最后由 lichence 于 2009-11-2 18:36 编辑 ]