发布网友 发布时间:2022-04-20 05:05
共2个回答
热心网友 时间:2023-08-06 09:40
//唉,上交了好几次都没交成功
以下程序VC编译成功,完全符合你的要求
不过对输入的购买金额有点要求,最好不要上亿。过这个坎,我就不保证能正确了。
#include<stdio.h>
#define Week 7
#define Mz 1 //设置基金的面值
#define SGfl 0.015 //设置申购费率
#define SHfl 0.005 //设置赎回费率
unsigned long cash; //购买金额
unsigned long quotient;//份额
float Netv[Week+1]; //每日净值
float avNet;//平均净值
void inquotient()//要求输入购买金额,并求得份额
{
int Right=0;
while(!Right)
{
printf("Please input your money(=>1000, and multiple):");
scanf("%ld",&cash);
if(cash % 1000==0) Right=1;
quotient=(long)(((float)cash-SGfl*(float)cash)/Mz);
}
}
void inNet()//要求输入每日净值,最后一个值为0,表示输入结束
{
int i;
Netv[0]=0;
printf("Please input everyday net value in this week: \n");
for(i=1;i<=Week;i++)
{
scanf("%f",&Netv[i]);
if(Netv[i]!=0) Netv[0]++;
else break;
}
}
main()
{
int i;
long CV,CP;//Current valuer ,Current Payoff,
float InR,sum=0;//increase Rate
inquotient();
inNet();
printf("Quotient Net Value Increase Rate Current Value Current Payoff\n");
for(i=1;i<=Netv[0];i++)
{
sum+=Netv[i];
if(i==1){ InR=(float)(Netv[i]-1)*100;}
else{
InR=Netv[i]-Netv[i-1];
InR=InR/Netv[i-1];
InR*=100;
}
CV=quotient*Netv[i];
CP=(long)(1-SHfl)*CV-cash;
printf("%ld %10.5f %11.2f%% %10d %10d\n",quotient,Netv[i],InR,CV,CP);
}
avNet=sum/Netv[0];
printf("Average Net Value in this week = %f %6.5f\n",sum,avNet);
}
热心网友 时间:2023-08-06 09:41
#include <stdio.h>
main(){
double weeknet[5];//第2列
double currentnet[5];//第4列
double everyrise[5];//第3列
double profitloss[5];//第5列
double weekaverage=0;
long int buy=0;
int fene;
int i;
printf("Please input your money(>1000, and multiple):");
scanf("%d",&buy);
while(buy<1000||buy%1000!=0){
printf("%d is not multiple of 1000.\n",buy);
printf("Please input your money(>1000, and multiple):");
scanf("%d",&buy);
}
printf("Please input everyday net value in this week:\n");
for(i=0;i<5;i++)
scanf("%lf",&weeknet[i]);//第2列
// printf("%f \n",weeknet[i]);
printf("Quotient Net Value Increase Rate Current Value Current Payoff\n");
fene=buy*0.985; //基金份额:9850,第1列
everyrise[0]=weeknet[0]-1;
for(i=0;i<5;i++){
currentnet[i]=fene*weeknet[i];//用户当前净值,第四列
if(i>0) everyrise[i]=(weeknet[i]-weeknet[i-1])/weeknet[i-1];//每日净值增长率,第三列
profitloss[i]=currentnet[i]*0.995-buy;//周平均净值,第五列
weekaverage+=weeknet[i];
}
weekaverage/=5;
for(i=0;i<5;i++)
printf("%d %.4f %.2f%% %.0f %.0f\n",fene,weeknet[i],everyrise[i]*100,currentnet[i],profitloss[i]);
printf("Average Net Value in this week = %f\n",weekaverage);
}
存成*.c文件,在VC下能编译通过