Home > Enterprise >  During compilation it is not asking for user input of rate and time
During compilation it is not asking for user input of rate and time

Time:10-05

// Q. Find out the simple interest. 


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

int main()
{

    int principal, rate, time;

    printf("principal\n");
    scanf("% d", &principal);

    printf("rate\n");
    scanf("% d", &rate);

    printf("time\n");
    scanf("% d", &time);

    printf("Simple interest is %d", principal * rate * time / 100);

    return 0;
}

CodePudding user response:

For scanf to work, you need to remove the space between the % and the d in the format strings: % d.

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

int main()
{

    int principal, rate, time;

    printf("principal\n");
    scanf("%d", &principal);

    printf("rate\n");
    scanf("%d", &rate);

    printf("time\n");
    scanf("%d", &time);

    printf("Simple interest is %d", principal * rate * time / 100);

    return 0;
}

Also, the program cannot ask for input during compilation. It will only ask for input when it is run.

  •  Tags:  
  • c
  • Related