Professional Documents
Culture Documents
Answer
Answer
Bing
The problem with your code is that you're trying to read the input with scanf
in a format that's not correct. The scanf function expects a format string that
specifies the type of data to be read, but you're providing a string with a
message. Here's the corrected version of your code:
#include <stdio.h>
#include <math.h>
int main()
{
int P, r, n, t;
printf("Enter Principal Amount: ");
scanf("%d", &P);
printf("Enter Rate: ");
scanf("%d", &r);
printf("Enter No. of times interest applied: ");
scanf("%d", &n);
printf("Enter time: ");
scanf("%d", &t);
return 0;
}
In this corrected version, I've added printf statements to prompt the user for
input, and I've corrected the scanf statements to properly read the input. Also,
note that in the calculation of Amount, I've cast r to float to ensure proper
division, and I've changed t to n*t to correctly calculate compound interest.
Please replace r, n, and t with appropriate values as per your requirements.
Remember that the rate of interest r should be in decimal form. For example, if
the rate of interest is 5%, then r should be 0.05.