[英]compound interest program problem in dev c++ using c
I am trying to write a program to print simple interest and compound interest in dev c++ in c programming but it is not printing the correct compound interest can anybody tell why?我正在尝试编写一个程序来在 c 编程中打印 dev c++ 中的单利和复利,但它没有打印正确的复利,谁能告诉为什么? here is my code:
这是我的代码:
#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;
}
You have given int instead of float.你给了 int 而不是 float。
#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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.