2-4 子序列的和
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int n,m;
int Case=0; //case报错 [Error] expected identifier or '(' before 'case'
while(scanf("%d %d",&n,&m)!=EOF&&(n&&m)){
int i=n;
float s=0.0;
for(;i<=m;i++)
s+=1/((float)i*(float)i);
printf("Case %d:%.5f\n",++Case,s);
}
return 0;
}
2-5 分数化小数(未解决)(%取余只针对整数)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int a,b,c;
int Case=0;
while(scanf("%d %d %d",&a,&b,&c)!=EOF&&(a&&b&&c)){
float i;
int j;
i=(float)a/(float)b;
if(i%(pow(0.1,c))>=0.5)
j=1;
else
j=0;
i=(int)(i/pow(0.1,c))+j;
i=(float)i*pow(0.1,c);
printf("Case %d:%f\n",++Case,i);
}
return 0;
}
2-6 排列(未解决)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int abc,def,ghi;
int i[10],j;
memset(i,0,sizeof(i));
for(abc=123;abc<=329;abc++){
int tag=1;
def=2*abc;
ghi=3*abc;
i[0]=1;
i[abc/100]++;i[abc%100/10]++;i[abc%10]++;
i[def/100]++;i[def%100/10]++;i[def%10]++;
i[ghi/100]++;i[ghi%100/10]++;i[ghi%10]++;
for(j=0;j<=9;j++)
{
if(i[j]!=1){
tag=0;break;
}
}
if(tag=1)
printf("%d %d %d\n",abc,def,ghi);
}
return 0;
}