“21天养成好习惯”第一期-13

今天遇到的奇特操作

(错解)

#include<stdio.h>
#include<math.h>
int main(){
int year,capital;
float rate;
char x;
printf("Input rate, year, capital:");
scanf("%f,%d,%d",&rate,&year,&capital);
printf("Compound interest (Y/N)?");
getchar();
scanf("%c",&x);
if(x=='Y')
printf("deposit  =  %.4f", capital * pow((1 + rate),year));
if(x=='N')
printf("deposit  =  %.4f" , capital  * (1 + rate * year));
return 0;
}
 

(正解)

#include <math.h>
int main()
{
    int year;
    double mon,rate;
    char choice;
    printf("Input rate, year, capital:");
    scanf("%lf,%d,%lf",&rate,&year,&mon);
    printf("Compound interest (Y/N)?");
    scanf(" %c",&choice);
    if(choice=='y' || choice=='Y')
    {
        printf("deposit = %.4f\n",mon*pow((1+rate),year));
    }
    else printf("deposit = %.4f\n",mon*(1+rate*year));
    return 0;
}
但二者似乎没有本质上的区别

但其实里面有换行(\n)

以及一些用法的不同(不一定错,但是可能不符合题目要求)

甚至有不可间的字符(一般是复制粘贴带来的)

导致了程序的运行结果的不同

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值