實驗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;
}

相關文章
相關標籤/搜索