This lab is to develop a C program to do the following computation,
A monkey collected a bunch of peaches. He ate half of the peaches and one more on the first day. On the following days, he ate half of the peaches that were left over from previous day and one more. And on the tenth day, before he started to eat, he found out there was only one peach left. Design a program to compute how many peaches the monkey collected at the beginning.
Hint: write down the formula first, then use loop to compute the result.
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
#include <stdio.h>
int main() {
int day=10;
int peaches=1;
do{
printf("On Day %d is was
%d\n",day,peaches);
day--;
peaches=peaches*2;
}while(day>1);
printf("Hence it was %d on day 1",peaches);
return 0;
}
output
Get Answers For Free
Most questions answered within 1 hours.