求 一编程题
- 提问者网友:不爱我么
- 2021-04-24 13:02
- 五星知识达人网友:末日狂欢
- 2021-04-24 13:08
//每个苹果0.8元,第一天买两个苹果,从第二天开始,每天买前一天的2倍,
//直到购买的苹果个数达到不超过100的最在数。编写程序求每天平均花多少钱?
#include <iostream.h>
int main( void )
{
int day;
int number;
float sum;
int temp;
sum = 0;
day = 0;
number = 2;
while( sum < 100 )
{
day++;
sum += number;
if( sum > 100 )
{
sum = sum -number;
day--;
break;
}
temp = 2 * number;
number = temp;
cout<<sum<<endl;
}
cout<<day<<"一共花费:"<<0.8*sum/day<<endl;
return 1;
}
- 1楼网友:持酒劝斜阳
- 2021-04-24 15:15
用vb写的,你看看行不。
Private Sub Command1_Click()
Dim Data As Integer Dim number As Integer Dim money1 As Single Dim money2 As Single Dim times As Integer Dim x As Integer Data = 1 number = 2 money = number * 0.8 money2 = money + money2 Print "**************" & vbCrLf & "第"; Data; "天" Print number; "个苹果" Print "今天花费"; money; "元" Print "累计共花费"; money2; "元" Do Until x >= 100 'DO循环,直到X大于100退出循环 If times = 2 Then Print "**************" & vbCrLf & "第"; Data; "天" Print number; "个苹果" Print "今天花费"; money; "元" Print "累计共花费"; money2; "元" Print "平均每天花费"; money2 / Data; "元" Else End If
Data = Data + 1 ' 增加一天 number = number * 2 ' 数量乘2 money = number * 0.8 '价格 money2 = money + money2 '总花费 x = number times = 2 Loop End Sub
- 2楼网友:迷人又混蛋
- 2021-04-24 13:50