C语言程序设计现代方法第二版课后习题 第二章习题

C语言程序设计现代方法第二版课后习题

1
#include <stdio.h>
int main(){
    printf("       *\n");
    printf("      *\n");
    printf("     *\n");
    printf("*   *\n");
    printf(" * *\n");
    printf("  *\n");
    return 0;
}
2
#include <stdio.h>
#include <math.h>
int main(){
    double r = 10;
    double pi = 2*asin(1.0);
    printf("Volume = %.2f\n", (4.0/3.0)*pi*r*r*r);
    return 0;
}
3
#include <stdio.h>
#include <math.h>
int main(){
    double r;
    double pi = 2*asin(1.0);
    printf("Radius: ");
    scanf("%lf", &r);
    printf("Volume = %.2f\n", (4.0/3.0)*pi*r*r*r);
    return 0;
}
4
#include <stdio.h>
int main(){
    double a;
    printf("Enter an amount: ");
    scanf("%lf", &a);
    printf("With tax added: $%.2f", 1.05*a);
    return 0;
}
5
#include <stdio.h>
int main(){
    double x;
    double answer;
    printf("x = ");
    scanf("%lf", &x);
    answer = 3*x*x*x*x*x + 2*x*x*x*x - 5*x*x*x - x*x + 7*x - 6; 
    printf("answer = %.2f", answer);
    return 0;
}
6
#include <stdio.h>
int main(){
    double x;
    double answer;
    printf("x = ");
    scanf("%lf", &x);
    answer = ((((3*x+2)*x-5)*x-1)*x+7)*x-6;
    printf("answer = %.2f", answer);
    return 0;
}
7
#include <stdio.h>
int main(){
    int dollar;
    int b20, b10, b5, b1;
    printf("Enter a dollar amount: ");
    scanf("%d", &dollar);
    b20 = dollar/20;
    b10 = (dollar - b20*20)/10;
    b5 = (dollar-b20*20-b10*10)/5;
    b1 = dollar-b20*20-b10*10-b5*5;
    printf("$20 bills: %d\n", b20);
    printf("$10 bills: %d\n", b10);
    printf(" $5 bills: %d\n", b5);
    printf(" $1 bills: %d\n", b1);
    return 0;
}
8
#include <stdio.h>
int main() {
    double loan, yrate, mrate, payment;
    double r1, r2, r3;
    printf("Enter amount of loan: \n");
    scanf("%lf", &loan);
    printf("Enter interest rate: \n");
    scanf("%lf", &yrate);
    printf("Enter monthly payment: ");
    scanf("%lf", &payment);
    mrate = yrate/1200;
    r1 = loan * (1 + mrate) - payment;
    r2 = r1 * (1 + mrate) - payment;
    r3 = r2 * (1 + mrate) - payment;
    printf("Balance remaining after first paymen: $%.2f\n", r1);
    printf("Balance remaining after second paymen: $%.2f\n", r2);
    printf("Balance remaining after third paymen: $%.2f", r3);
    return 0;
}

本人在通过《C语言程序设计:现代方法(第2版)》自学C语言,想在学习的过程中将做出的答案分享出来,可能会存在错误的地方,如有错误的地方还希望大家能够指出相互学习。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值