第三章 课后习题

3.2 输出一个三位数的逆序数,忽略负号。

 #include<stdio.h>
#include<math.h>
int main()
{
    int x,y;
    scanf("%d",&x);
    x=fabs(x);
    int a0,a1,a2;
    a0=x/100;
    a1=x%100/10;
    a2=x%10;
    y=a2*100+a1*10+a0;
    printf("%d",y);

    return 0;
}

注意:math.h的绝对值函数是fabs(),不是abs()。

 

3.3 年利率为2.25%,已知存款期为n年,存款本金为capital元,输出n年后的本金利息之和deposit。

#include<stdio.h>
#include<math.h>
int main()
{
    double rate,n,capital,deposit;
    //原题是输入的方式,为了简单就u用赋值来做
    rate=0.0225;
    n=2;
    capital=10000;
    deposit=capital*pow(1+rate,n);
    printf("%lf",deposit);
    return 0;
}

 

3.4 输出一元二次方程的两个解。

#include<math.h>
#include<stdio.h>
int main()
{
    double a,b,c,x1,x2;
    printf("Please enter a,b,c:\n");
    scanf("%lf,%lf,%lf",&a,&b,&c);
    double temp;
    temp=sqrt(b*b-4*a*c);
    x1=(-b+temp)/(2.0*a);
    x2=(-b-temp)/(2.0*a);
    printf("%lf %lf",x1,x2);
    return 0;
}

注意:开方是sqrt()

转载于:https://www.cnblogs.com/SlowIsFast/p/10393292.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值