题目:
小明今年12岁,他母亲比他大24岁。编写一个程序计算小明的母亲在几年后比小明的年龄大一倍,那时他们两人的年龄各是多少?
**输出格式要求:“year=%d\n” “mingAge=%d\n” “motherAge=%d\n”
程序运行示例如下:
year=12
mingAge=24
motherAge=48
程序:
#include <stdio.h>
int main()
{
int a=12,b=12+24,i=0;
for (i=1; ;i++)
{
a++;
b++;
if (a*2==b)
{
break;
}
}
printf("year=%d\n",i);
printf("mingAge=%d\n",a);
printf("motherAge=%d\n",b);
return 0;
}
是吧真的很简单!但你这个憨憨一开始没看到“+12”弄了半天都是year=0我真是没有话讲。而且还在那里a=a+1。以头抢地。