1个回答
展开全部
仅供参考:
#include "stdio.h"
int firetime(int a,int b); //计算蜡烛燃烧时间
void main()
{
int a,b;
int sum;
printf("请输入蜡烛根数:");
scanf("%d",&a);
printf("多少根烧完的蜡烛可以搓成1根新蜡烛:");
scanf("%d",&b);
sum = firetime(a,b);
printf("这些蜡烛可以烧%d分钟。\n",sum);
}
int firetime(int a,int b)
{
int time_sum = 0; //燃烧时间
int lazhu_new =a; //蜡烛根数
int lazhu_old =0; //烧完的蜡烛
while(1)
{
time_sum += lazhu_new; //蜡烛燃烧过程
lazhu_old += lazhu_new; //蜡烛烧完,当前烧完的蜡烛的总数
if(lazhu_old < b) //如果烧完的蜡烛不够搓成一根,则退出循环
{
break;
}
lazhu_new = lazhu_old/b; //将b跟烧完的蜡烛搓成一根新的蜡烛
lazhu_old -= lazhu_new * b; //还剩下的烧完蜡烛数
}
return time_sum;
}
#include "stdio.h"
int firetime(int a,int b); //计算蜡烛燃烧时间
void main()
{
int a,b;
int sum;
printf("请输入蜡烛根数:");
scanf("%d",&a);
printf("多少根烧完的蜡烛可以搓成1根新蜡烛:");
scanf("%d",&b);
sum = firetime(a,b);
printf("这些蜡烛可以烧%d分钟。\n",sum);
}
int firetime(int a,int b)
{
int time_sum = 0; //燃烧时间
int lazhu_new =a; //蜡烛根数
int lazhu_old =0; //烧完的蜡烛
while(1)
{
time_sum += lazhu_new; //蜡烛燃烧过程
lazhu_old += lazhu_new; //蜡烛烧完,当前烧完的蜡烛的总数
if(lazhu_old < b) //如果烧完的蜡烛不够搓成一根,则退出循环
{
break;
}
lazhu_new = lazhu_old/b; //将b跟烧完的蜡烛搓成一根新的蜡烛
lazhu_old -= lazhu_new * b; //还剩下的烧完蜡烛数
}
return time_sum;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询