《C语言程序设计现代方法:第2版 修订版》第二章课后编程题,水平有限,仅供参考 1
#include <stdio.h>
int main (void)
{
printf(" *\n");
printf(" *\n");
printf(" *\n");
printf("* *\n");
printf(" * *\n");
printf(" * \n");
return 0;
}
2
#include <stdio.h>
#define PI 3.14
int main (void)
{
int ra;
float volum;
ra=10;
volum=4.0f/3.0f*PI*ra*ra*ra;
printf("The volum of the ball is %f",volum);
return 0;
}
3
#include <stdio.h>
#define PI 3.14
int main (void)
{
int ra;
float volume;
printf("Please enter the ra of the ball:");
scanf("%d",&ra);
volume=4.0f/3.0f*PI*ra*ra*ra;
printf("The volume of the ball is:%f",volume);
return 0;
}
4
#include <stdio.h>
int main (void)
{
float num;
printf("Enter an amount:");
scanf("%f",&num);
printf("With tax added:$%.2f",num*1.05);
return 0;
}
5
#include <stdio.h>
int main (void)
{
int num;
printf("Please enter a num:");
scanf("%d",&num);
printf("%d",3*num*num*num*num*num+2*num*num*num*num-5*num*num*num-num*num+7*num-6);
return 0;
}
6
#include <stdio.h>
int main (void)
{
int num;
printf("Please enter a num:");
scanf("%d",&num);
printf("%d",((((((3*num+2)*num)-5)*num)-1)*num+7)*num-6);
return 0;
}
7
#include <stdio.h>
int main (void)
{
int num,num_20,num_10,num_5,num_1;
printf("Enter a doollar amount:");
scanf("%d",&num);
num_20=num/20;
num_10=(num-num_20*20)/10;
num_5=(num-num_20*20-num_10*10)/5;
num_1=(num-num_20*20-num_10*10-num_5*5);
printf("$20 bills:%d\n",num_20);
printf("$10 bills:%d\n",num_10);
printf("$10 bills:%d\n",num_5);
printf("$10 bills:%d\n",num_1);
return 0;
}
8
#include <stdio.h>
int main (void)
{
float amount,rate,monthly_payment,remain;
printf("Enter amount of loan:");
scanf("%f",&amount);
printf("Enter interest rate:");
scanf("%f",&rate);
printf("Enter monthly payment:");
scanf("%f",&monthly_payment);
remain=(amount-monthly_payment)+amount*rate/1200;
printf("Banlance remaining after first payment:$%.2f\n",remain);
remain=(remain-monthly_payment)+remain*rate/1200;
printf("Banlance remaining after second payment:$%.2f\n",remain);
remain=(remain-monthly_payment)+remain*rate/1200;
printf("Banlance remaining after third payment:$%.2f",remain);
return 0;
}
|