存钱c语言
时间: 2023-06-21 22:17:58 浏览: 252
实现存钱功能的C语言代码如下:
```c
#include <stdio.h>
int main() {
float balance = 0; // 初始余额为0
float money; // 要存的金额
printf("请输入要存的金额:");
scanf("%f", &money);
balance += money; // 存钱操作
printf("存钱成功!当前余额为%.2f元。\n", balance);
return 0;
}
```
这段代码中,我们定义了一个初始余额为0的变量`balance`和一个要存的金额变量`money`,然后通过`scanf`函数从用户输入中读取要存的金额,最后将要存的金额加到余额中并输出结果。
相关问题
c语言存款利率计算器
以下是一个简单的C语言存款利率计算器的例子:
```c
#include <stdio.h>
#include <math.h>
int main() {
double principal, rate, interest;
int years, compound; char choice;
printf("Enter the principal amount: ");
scanf("%lf", &principal);
printf("Enter the annual interest rate: ");
scanf("%lf", &rate);
printf("Enter the number of years: ");
scanf("%d", &years);
printf("Do you want to compound interest (Y/N)? ");
scanf(" %c", &choice);
if (choice == 'Y' || choice == 'y') {
printf("Enter the number of times interest is compounded per year: ");
scanf("%d", &compound);
interest = principal * pow(1 + rate / compound, compound * years) - principal; } else {
interest = principal * rate * years;
}
printf("Total amount at maturity: %.4f\n", principal + interest);
return 0;
}
```
pta计算存款利息c语言
这是一道计算存款利息的C语言题目。根据给出的计算公式,我们可以编写如下代码:
#include <stdio.h>
#include <math.h>
double sum;
double money, rate, year;
int main() {
scanf("%lf", &money);
scanf("%lf", &year);
scanf("%lf", &rate);
sum = money * pow((1 + rate), year) - money;
printf("interest = %.2f", sum);
return 0;
}