设计一个C语言程序来计算到期存款本息之和

2024-11-22 22:50:09
推荐回答(2个)
回答(1):

#include
void main()
{
int b,q;
float h;
printf("请依次输入存款的本金和期限:"\n);
scanf("%d",&b);
scanf("%d",&q);
switch(q)
{
case 1: h=(1+0.0225)*b;
printf("本息和为:%f\n",h);
case 2: h=(1+0.0243)*b;
printf("本息和为:%f\n",h);
case h=(1+0.027)*b;
printf("本息和为:%f\n",h);
case h=(1+0.0288)*b;
printf("本息和为:%f\n",h);
case h=(1+0.03)*b;
printf("本息和为:%f\n",h);
defailt: printf("输入有误!");
}
}

回答(2):

#include

void main()
{
int a;
double x,y,z;

printf("请选择存期: ");
scanf("%d",&a);
printf("\n请存入本金: ");
scanf("%lf",&x);

if(a==1)
{
y = x * 0.025 * 1;
printf("\n利息为: %7.2lf\n",y);
}
else if(a==2)
{
y = x * 0.027 * 2;
printf("\n利息为: %7.2lf\n",y);
}
else if(a==3)
{
y = x * 0.0324 * 3;
printf("\n利息为: %7.2lf\n",y);
}
else if(a==5)
{
y = x * 0.036 * 5;
printf("\n利息为: %7.2lf\n",y);
}

z = x + y;

printf("本息为: %7.2lf\n",z);
}

把数字改下就可以了