网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
08月25日漏签0天
c语言吧 关注:799,035贴子:4,359,268
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 7回复贴,共1页
<<返回c语言吧
>0< 加载中...

不可以运行,不知道哪里错了

  • 只看楼主
  • 收藏

  • 回复
  • 直线娃娃
  • 毛蛋
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
这道题是一个人点n个蜡烛,一个烧到还剩一点不可以烧了之后再点下一个,k个剩下的残蜡可以再做成一个新的蜡烛(k>1),输入的数是n和k,想要算出他一共可以点多少根蜡烛。例如n=5, k= 3,答案就是7,因为前三根蜡烛点完了可以制成一个新的,这个新的再加上后两根点完了之后,又可以制成一个新的,一共就是7根。
#include <stdio.h>
int count_candles(int, int)
int main(void) {
int candle, res //number of candles and number of residuals
printf("Enter number of candles and \n");
printf("number of residuals to make a new candle: ");
scanf("%d %d", &candle, &res);
printf("Total candles burnt = %d\n", count_candles(candle, res));
return 0;}
int count_candles(int total, int left) {
int NumLeft=left;
do {
total = total + total/res;
NumLeft = NumLeft/res + NumLeft%res;
} while (NumLeft<left);
return total;
}
candles.c: In function 'count_candles':
candles.c:16:16: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
candles.c:31:40: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
candles.c:13:1: error: parameter name omitted
candles.c:13:1: error: parameter name omitted
candles.c:41:1: error: expected '{' at end of input
candles.c:41:1: warning: control reaches end of non-void function
下面这些是报错,我不太明白这些报错。。可以帮我看一下不~


  • QHearting
  • 超能力者
    9
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
我初学者,不知道对不对啊


2025-08-25 21:32:02
广告
不感兴趣
开通SVIP免广告
  • 木星GG
  • 低能力者
    5
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
语法错误自己查吧


  • Asyfupid
  • 大能力者
    8
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
不用循环。
#include <stdio.h>
int count_candles(int, int);
int main()
{
int candle, res; //number of candles and number of residuals
printf("Enter number of candles and \n");
printf("number of residuals to make a new candle: ");
scanf("%d %d", &candle, &res);
printf("Total candles burnt = %d\n", count_candles(candle, res));
return 0;
}
int count_candles(int total, int left)
{
int rst = total+total/(left-1);
if(total%(left-1) == 0)
rst--;
return rst;
}



登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 7回复贴,共1页
<<返回c语言吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示