这道题是一个人点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
下面这些是报错,我不太明白这些报错。。可以帮我看一下不~
#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
下面这些是报错,我不太明白这些报错。。可以帮我看一下不~