1)
#include "stdio.h"
int main(int argc,char *argv[]){
double x;
printf("Please enter x(R: 0if(scanf("%lf",&x)!=1 || x<=0 || x>=1000){
printf("Invalid number!\n");
return 0;
}
printf("%d is %s\n",(int)x,(int(x)&1 ? "ODD.\n" : "EVEN.\n"));
return 0;
}
运行样例:
2)
#include "stdio.h"
int main(int argc,char *argv[]){
double w,r;
int l;
printf("Please enter w & l(R: w>=0, int l>=0)...\n");
if(scanf("%lf%d",&w,&l)!=2 || w<=0 || l<1){
printf("Input error, exit...\n");
return 0;
}
if(l<=6)
r=0.061;
else if(6r=0.0656;
else if(12r=0.0665;
else if(l>36)
r=0.069;
printf("After %d month(s) shall repay the principal and interest, a total of %g yuan.\n",l,w*r+w);
return 0;
}
运行样例:
3)
#include "stdio.h"
int main(int argc,char *argv[]){
int n,t,m;
printf("Please enter a positive integer no more than 3 digits...\n");
if(scanf("%d",&n)!=1 || n>999 || n<1){
printf("Input error, exit...\n");
return 0;
}
for(m=0,t=n;t;t/=10,m++);
printf("%d is %d digit(s)...\n",n,m);
for(m=1,t=n;t;t/=10,m*=10);
for(m/=10;m;printf("%d ",n/m%10),m/=10);
printf("\n");
while(n){
printf("%d ",n%10);
n/=10;
}
printf("\n");
return 0;
}
运行样例: