#include
void main()
{
int num,sum;
char *a[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Oct","Sep","Nov","Dec"};
printf("请输入一个三位数的正整数:\n");
scanf("%d",&num);
if(num<100||num>999)
{
printf("输入有误!\n");
return;
}
sum=num/100+num%10+(num/10)%10;
if(sum>0&&sum<13)
printf("%s\n",a[sum-1]);
else
printf("***\n");
}
给你一个程序段:int sun(int m)
{
int g,s,b;//g个位数,s十位数,b百位数
b=m/100;
s=m/100/10;
g=m%10;
return g+s+b ;
}
#include
int main()
{
char* month[12] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
char n[1000],*p;
int sum=0,bg=0;
scanf("%s",n);
p = n;
while(*p)
{
sum += *p - '0';
if(bg) putchar('+');
putchar(*p);
p++;
bg = 1;
}
printf("=%d->",sum);
if(sum>12||sum<=0)
{
printf("***\n");
}
else
{
printf("%s\n",month[sum-1]);
}
}
测试运行 完全正常
#include
int main()
{
int s,a,b,c,sum=0;
char *month[12]= {"January","February","March","April","May",
"June","July","August","September","October","November","December "};
scanf("%d",&s);
a=s/100;
b=s/100/10;
c=s%10;
sum =a+b+c;
printf ("%d+%d+%d=%d->",a,b,c,sum);
if (sum>=1 && sum<=12)
{
printf("%s\n",month[sum-1]);
}
else
{
printf("***\n");
}
return 0;
}
#include
#include
#define MONTH 12
void main()
{
char *month[MONTH] = {"January","February","March","April","May","June","July","August","Semtember","October","November","December"};
int number = 0;
int sum = 0;
printf("please input a int number between 100 and 999:\n");
do
{
scanf("%d",&number);
if (number<100||number>999)
{
printf("invalid number,please input again\n ");
}
} while (number<100||number>999);
sum = number/100 + number%100/10+number%100%10;
if (sum >=1 && sum <=12)
{
printf("month:%s\n",month[sum -1]);
}
else
{
printf("sum = %d\n",sum);
}
}
把分给我啊,我已经给你调试好了啊