Turbo C 给出的输出为 0.000000

Turbo C gives Output as 0.000000

我已经为 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

有什么帮助吗?

变化:

scanf("%f",&n);

至:

scanf("%d",&n);

因为 n 是一个整数,而不是浮点数,正如评论中已经建议的那样。

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

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