编辑为了清晰.我为混乱而道歉:3
好吧,所以我正在关注一个在线CS课程,我们应该用C语言编写一个程序,它会告诉你如果你在月初有一分钱并且加倍一分钱你会有多少钱每天.
每天你会得到你昨天的两倍加上前几天的一切.
示例:您从.01开始,以及在第3天计算运行总计的内容.因此第一天是.01,第二天是.02,第三天是.04.在第3天,你将有0.01 + 0.02 + 0.04(.09).
该计划打算在任何给定月份(28-31天)的持续时间内计算此过程.
我正在努力实现这一点.我已经把它翻了一倍,但我不确定如何将之前计算的日子放在一起.
这是我的代码:
#include <stdio.h>
#include <math.h>
int main(void) {
/*days represents total days in months*/
/*pens represents the number of pennies on the first day*/
long long days;
long long pens;
do {
printf("Enter the number of days in the month: ");
scanf("%llu", &days);
} while(days < 28 || days > 31);
printf("Enter the initial number of pennies: ");
scanf("%llu", &pens);
for (int i=0; i<= days-1; i++) {
pens += pow(2,i); …
Run Code Online (Sandbox Code Playgroud) c ×1