forked from hermanwongkm/CS1010
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Candles.c
38 lines (31 loc) · 992 Bytes
/
Candles.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* CS1010 AY2016/7 Semester 1 Lab2 Ex1
* candles.c
* <Calculate the total number of candles that can be burned>
* <Wong Kai Min Herman>
* <T13>
*/
#include <stdio.h>
int count_candles(int ,int);
int main(void) {
int candles,residuals;
printf("Enter number of candles and \n");
printf("number of residuals to make a new candle: ");
scanf("%d", &candles);
scanf("%d", &residuals);
printf("Total candles burnt = %d\n", count_candles(candles,residuals));
return 0;
}
//This functions takes in the num of candles and residual and calculate the number of extra candles that can be made and add into initial num of candles.
//Pre condition: Inputs are positive.
int count_candles(int c,int r){
int counter, candle;
candle = c; //Initial number of candles
while(c >= r){
c -= r; //Minus away required residual
c ++; //Make additional new candle
counter ++;
}
candle = candle + counter;
return candle;
}