首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用C语言实现开发c++中的复合兴趣程序问题

用C语言实现开发c++中的复合兴趣程序问题
EN

Stack Overflow用户
提问于 2021-12-12 08:40:26
回答 1查看 86关注 0票数 0

我正在尝试编写一个程序,在dev c++中打印简单兴趣和复合兴趣,但它没有打印正确的复合兴趣,谁知道为什么?这是我的代码:

代码语言:javascript
复制
#include<stdio.h>
#include<math.h>
int main()
{
int p,r,t,si,ci;
printf("enter the principle:");
scanf("%d",&p);
printf("enter the rate:");
scanf("%d",&r);
printf("enter the time:");
scanf("%d",&t);
si=p*r*t/100;
ci=p*pow((1+(r/100)),t);
printf("simple interest:%d",si);
printf("\ncompound interest:%d",ci);
int a=getch();
return 0;
}
EN

回答 1

Stack Overflow用户

发布于 2021-12-12 09:32:38

你给出的是int而不是浮点。

代码语言:javascript
复制
#include<stdio.h>
#include<math.h>
int main(){
    float p,r,t,si,ci;
    printf("enter the principle:");
    scanf("%d",&p);
    printf("enter the rate:");
    scanf("%d",&r);
    printf("enter the time:");
    scanf("%d",&t);
    si=p*r*t/100;
    ci=p*pow((1+(r/100)),t);
    printf("simple interest:%d",si);
    printf("\ncompound interest:%d",ci);
    int a=getch();
    return 0;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70322098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档