Turbo C的输出为0.000000

时间:2019-01-27 15:08:39

标签: c turbo-c

我为Turbo C设置了正确的目录路径。但是,它给出的输出为0.000000

以下是程序:

#include <conio.h>
#include <math.h>
#include <stdio.h>

void main() {
    int n;
    float r, si, ci, p;
    clrscr();
    printf("enter principle amount\n");
    scanf("%f", &p);
    printf("enter rate of interest\n");
    scanf("%d", &r);
    printf("enter number of years\n");
    scanf("%f", &n);
    si = p * n * r / 100;
    ci = p * (pow((1 + (r / 100)), n) - 1);
    printf("simple interest=%f\n", si);
    printf("compound interest=%f", ci);
    getch();
}

应该输入数字而不是0.000000

有帮助吗?

1 个答案:

答案 0 :(得分:1)

更改:

scanf("%f",&n);

收件人:

scanf("%d",&n);

因为n是整数,而不是注释中所建议的浮点数。

对于r类型的float,您应该使用scanf("%f",&r);

PS:考虑使用现代编译器,例如GCC。