实验1

#第一题 缩写程序,输出如下信息: **********¥¥ ¥¥¥ This is my first C program! **********¥¥¥¥¥编程

#include<stdio.h>
int main(){
	printf("********¥¥\n");
	printf("¥¥¥\n");
	printf("This is my first C program\n");
	printf("********¥¥¥¥¥\n");
	return 0;
}

#第二题 .输入圆柱的半径 r 和高 h,计算并输出其体积rest

#include<stdio.h>
#define x 3.14
int main()
{
	float a, b, c;
	printf("输入圆柱底面半径\n");
	scanf("%1f",&a);
	printf("请输入圆柱的高:\n");
	scanf("%1f", &b);
	c = (x * a * a) * b;
	printf("圆柱体的体积是:%.21f", c);
	return 0;
}

#第三题 输入三个数到变量 a,b,c 中,求它们的平均值。code

#include <stdio.h>


int main()
{

    int a, b,c;
    float aver;
    printf("请输入a:\n");
    scanf("%d", &a);
    printf("请输入b:\n");
    scanf("%d", &b);
    printf("请输入c:\n");
    scanf("%d", &c);
    aver = (a + b + c) / 3.0;
    printf("平均值为:%f", aver);
    return 0;
}

#第四题 输入秒数,将它按小时.分钟.秒的形式来输出。例如输入 24680,则输出 6 小时 51 分 20 秒blog

#include<stdio.h>
 int main()
{
	int a, b, c, d;
	printf("输入秒数:\n");
	scanf("%d",&a);
	b = a / 3600;
	c = (a % 3600) / 60;
	d = a % 3600 % 60;
	printf("%d秒=%d小时%d分钟%d秒", a, b, c, d);
	return 0;
}

#第五题rem

(1)编写一个计算球体体积的程序,其中球体半径为 10m(注意分数的写法) (2)修改上题中的程序,使用户能够自行输入球体的半径it

#include<stdio.h>
#define x 3.14
int main()
{
	float r,v;
	printf("输入半径:\n");
	scanf("%f", &r);
	v = 4 / 3 * x * r * r * r;
	printf("体积为:%f",v);
	return 0;
}

#第6题 6.编写一个程序,使用 printf 在屏幕上显示下面的图形: * * *io

#include<stdio.h>
void main() {
	printf("             *\n");
	printf("            *\n");
	printf("      *    *\n");
	printf("       *  *\n");
	printf("        *\n");
}

#第七题 编写一个程序,要求用户输入一个美圆变量,而后显示出增长 5%税率后的相应金 额,格式以下所示 Enter an amount: 100.00 With tax added:$105.00class

#include<stdio.h>
int main() {
	float a, b;
	printf("请输入金额:");
	scanf("%f", &a);
	b = a * 1.05;
	printf("最后结果金额:%.2f", b);
	return 0;
}
原答案
int main()
{
	float money, moneyWithTax;
	printf("Enter an amount:");
	scanf("%f", &money);
	moneyWithTax = money * 1.05;
	printf("With tax added:$%.2f", moneyWithTax);

	return 0;
}

#第8题 )编程要求用户输入 x 的值,而后显示以下多项式的值: 3x5+2x4-5x3-x2+7x-6 (2)修改上题,用以下公式对多项式求值 ((((3x+2)x-5)x-1)x+7)x-6变量

#include <stdio.h>
#include<math.h>

int main()
{
    int x, f1, f2;
    printf("请输入X的值=");
    scanf("%d", &x);
    f1 = 3 * pow(x, 5) + 2 * pow(x, 4) - 6 * pow(x, 3) - pow(x, 2) + 7 * x - 6;
    f2 = (((3 * x + 2) * x - 1) * x + 7) * x - 6;
    printf("f1=%d\n", f1);
    printf("f2=%d\n", f2);
    return 0;
}

#第九题 编写一个程序,要求用户输入一个美金数量,而后显示出如何用最少的 20 美圆、10 美圆、5 美圆和 1 美圆来付款 Enter a dollar amount:93 $20 bills:4 $10 bills:1 $5 bills:0 $1 bills:3 (提示:将付款金额除以 20,肯定 20 美圆的数量,而后从付款金额中减去 20 美圆的 总金额,对其余面值的钞票重复这一操做,确保在程序中使用整数值,不要使用浮点数float

#include<stdio.h>
int main() {
	int a, b, c, d, e;
	printf("请输入金额:");
	scanf("%d", &a);
	b = a / 20;
	c = a % 20 / 10;
	d = a % 20 % 10 / 5;
	e = a % 5;
	printf("20$须要:%d张\n", b);
	printf("10$须要:%d张\n", c);
	printf("5$须要:%d张\n", d);
	printf("1$须要:%d张\n", e);
}

#第十题 编程计算第1、第2、第三个月还贷后剩余的贷款技能 Enter amount of loan:20000.00 Enter interest rate:6.0 Enter monthly payment:386.66 Balance remaining after first payment:$19713.34 Balance remaining after secomd payment:$19425.25 Balance remaining after third payment:$19135.71 在显示每次还款后的余额时保留两位小数(提示:每一个月的贷款余额减去还款金额后 还须要加上贷款余额与月利率的乘积。月利率的计算方法是把用户输入的利率转换成百分 数再除以 12)

#include<stdio.h>
int main() {
	float bj, lilv, money1, money2, money3;
	printf("输入你原来的贷款:\n");
	scanf("%f", &bj);
	printf("利率:\n");
	scanf("%f", &lilv);
	money1 = bj / lilv / 12;
	money2 = (bj - money1) / lilv / 12;
	money3=(bj-money1-money2) / lilv / 12;
	printf("第一次付钱后:%.2f\n", bj - money1);
	printf("第二次付钱后:%.2f\n", bj - money1-money2);
	printf("第三次付钱后:%.2f\n", bj - money1-money2-money3);
	return 0;
}

相关文章
相关标签/搜索