




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、#include <stdio.h> main() (const double pi = 3.14159;double r;double circum;double area;printf("Input r:"); scanf("%lf", &r); circum = 2 * pi * r; area = pi * r * r; printf("printf WITHOUT width or precision specifications:n"); printf("circumference = %f,
2、 area = %fn", circum, area);printf("printf WITH width and precision specifications:n"); printf("circumference = %7.2f, area = %7.2fn", circum, area); 使用const常量定義圓周率 pi (取值為3.14159),編程從鍵盤輸入圓的半徑r,計(jì)算并輸出圓的周長和面積.輸出的數(shù)據(jù)保存兩位小數(shù)點(diǎn).*輸入格式要求:"lf"提示信息:"Input r:" *輸出格式要求
3、:"printf WITHOUT width or precision specifications:n" "circumfer ence = %f, area = %fn" "printf WITH width and precision specifications:n" "circumfere nce = %7.2f, area = %7.2fn"程序運(yùn)行例如如下: Input r:5.3 printf WITHOUT width or precision specifications: circumfere
4、nce = 33.300854, area = 88.247263 printf WITH wid th and precision specifications: circumference = 33.30, area = 88.25#include<stdio.h> main()(int a,b,c;double p,q,x1,x2;printf("Please enter the coefficients a,b,c:");scanf("%f,%f,%f",&a,&b,&c);p=-b/a;q=(bA2-4ac)
5、A0.5/(2a);x1=p-q;x2=p+q;#include<stdio.h>Main()(int a,b,c;double p,q,x1,x2;printf("Please enter the coefficients a,b,c:");scanf("%f,%f,%f",&a,&b,&c);p=-b/a;q=(bA2-4ac)A0.5/(2a);x1=p-q;x2=p+q;)計(jì)算輸入的兩個(gè)整數(shù)的和.*輸入格式要求:"d提示信息:請輸入第一個(gè)整數(shù):""請輸入第二個(gè)整數(shù):"*輸
6、出格式要求:"d + %d = %dn"程序運(yùn)行例如如下: 請輸入第一 個(gè)整數(shù):34請輸入第二個(gè)整數(shù): 56 34 + 56 = 90#include <stdio.h> int main()(int n1;定義第一個(gè)整型變量n1int n2;定義第一個(gè)整型變量n2printf("請輸入第一個(gè)整數(shù):");務(wù)必養(yǎng)成好習(xí)慣:任何輸入前先給出輸入提示!scanf("%d", &n1);接收第一個(gè)整數(shù) n1printf("請輸入第二個(gè)整數(shù):");務(wù)必養(yǎng)成好習(xí)慣:任何輸入前先給出輸入提示!scanf(&q
7、uot;%d", &n2);接收第二個(gè)整數(shù) n2printf("%d + %d = %dn", n1, n2, n1 + n2);/*每一個(gè)格式限制符 d限制后面的一項(xiàng),第一個(gè) d限制n1 ,第二個(gè)d限制n2第三個(gè)限制n1+n2 , %用于限制輸出項(xiàng)以十進(jìn)制有符號(hào)整數(shù)的形式輸出,其它的格式限制字符串中的字符,如+,=等原樣輸出,n為換行符*/return 0; )學(xué)校有近千名學(xué)生(大于等于900,小于1000),在操場上排隊(duì),5人一行余2人,7人一*輸出格式要求:"there a行余3人,3人一行余1人,編寫一個(gè)程序求該校的學(xué)生人數(shù).re %d
8、students in the groundn"#include <stdio.h> int main()int n;for | (n = 900; n < 1000; n+)"|if (n % 5 = 2 && n % 7 = 3&& n % 3 = 1)printf("there are %d students in the groundn", n);)(假設(shè)對折一弓厚度為 0.1mm的紙,請問要對折多少次才能使紙的厚度從地球到達(dá)月球(假 設(shè)地球到月球的距離為30萬km)?*輸出格式要求:"
9、%d"#include <stdio.h>#include <math.h>int main() printf("%d", (int)ceil(log10(3.0) + 12) / log10(2.0);return 0;請使用short int型的變量計(jì)算兩個(gè) 7位十進(jìn)制整數(shù)的和,要求使用盡可能少的變量.* *輸入格式要求:"a = %3hd%4hd, b = %3hd%4hd"* *輸出格式要求:"a + b = %d"程序運(yùn)行例如如下:a = 1234567,b = 7654321輸出a + b
10、 = 8888888#include <stdio.h>int main()short int d, m, c, n;scanf("a = %3hd%4hd, b = %3hd%4hd", &d, &m, &c, &n);printf("a + b = %d", (d + c) * 10000 + m + n);return 0;華氏和攝氏溫度的轉(zhuǎn)換公式為:C = 5/9 x (F-32)其中,C表示攝氏溫度,F表示華氏溫度.要求:華氏0 丁300 下,每隔20 丁輸出一個(gè)華氏溫度對應(yīng)的攝氏溫度值.* *輸入提
11、示信息要求:無* *輸入數(shù)據(jù)格式要求:無* *輸出數(shù)據(jù)格式要求:"4.0f%10.1fn"(第一個(gè)浮點(diǎn)數(shù)為華氏溫度,第二個(gè)浮點(diǎn)數(shù)為攝氏溫度)#include <stdio.h>int main()int upper, step;float f = 0, c;upper = 300;step = 20;while (f <= upper)c = 5.0 / 9 * (f - 32);printf("%4.0f%10.1fn", f, c);f = f + step;)return 0;編程輸出以下形式的乘法九九表:1*1= 1 2*1=
12、2 2*2= 4 3*1= 3 3*2= 6 3*3= 9 4*1 =4 4*2= 8 4*3=12 4*4=16 5*1= 5 5*2=10 5*3=15 5*4=20 5*5=25 6*1= 6 6*2=12 6* 3=18 6*4=24 6*5=30 6*6=36 7*1= 7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=498*1= 8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 9*1= 9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=
13、81 *輸出格式要求:"%1d*%1d=%2d #include <stdio.h> main() int i,j;for(i=1;i<=9;i+)for(j=1;j<=i;j+)-1printf("%d*%d=%2d ",i,j,i*j);printf("n");小明今年12歲,他母親比他大 24歲.編寫一個(gè)程序計(jì)算小明的母親在幾年后比小明的年 齡大一倍,那時(shí)他們兩人的年齡各是多少*輸出格式要求:"year=%dn" "mingAge=%dn" "motherAge=%
14、dn" 程序運(yùn)行例如如下:year=12mingAge=24motherAge=48#include <stdio.h> int main() int mingAge, motherAge, year;mingAge = 12;motherAge = mingAge + 24;year = 1;while (motherAge + year) != 2 * (mingAge + year) year = year + 1;)printf("year=%dn", year);printf("mingAge=%dn", mingAge
15、+ year);printf("motherAge=%dn", motherAge + year);return 0;)用二維數(shù)組作為函數(shù)的參數(shù),實(shí)現(xiàn)并輸出矩陣的轉(zhuǎn)置和轉(zhuǎn)置后矩陣副對角線元素之和.按如下函數(shù)原型編程計(jì)算. 其中n的值由用戶從鍵盤輸入. 使用ProduceMatrix函數(shù)生成n階方 陣,以start值作為矩陣的第一個(gè)元素 all ,每行下一個(gè)元素比該行上一個(gè)元素大1,每行第一個(gè)元素比上一行最后一個(gè)元素大1.例如n=3,start=3時(shí)ProduceMatrix生成的矩陣為:3456789 1011m和n的取值范圍為1,30.函數(shù)原型為void Transpos
16、e(int a口N,int n);void ProduceMatrix(int a口N,int n,int start);void PrintMatrix(int atN, int n);int SumCounterDiagonal(int aN,int n); / 求矩陣副對角線元素之和 輸入提示信息:"Input n:n" "Input %d*%d matrixs start element:n 輸入格式:"d"輸出提示信息和格式:"The transposed matrix is:n""The sum of
17、the matrix-counter-diagonal is:%dn"輸出格式(輸完矩陣的一行要換行):"4d注意除了 PrintMatrix外的輸入輸出均在 main函數(shù)里面#include<stdio.h>#define N 30void Transpose(int a口N, int n);void ProduceMatrix(int a口N, int n, int start);void PrintMatrix(int a口N, int n);int SumCounterDiagonal(int aN, int n);int main() int n ,
18、sum = 0, start = 0;int aNN = 0;/1printf("Input n:n");scanf("%d", &n);printf("Input %d*%d matrixs start element:n", n, n);scanf("%d", &start);/1ProduceMatrix(a, n, start);Transpose(a, n);/1printf("The transposed matrix is:n");PrintMatrix(a, n);/1sum = SumCounterDiagonal(a, n);printf("The sum of the matrix-counter-diagonal is:%dn", sum); return 0; void Produc
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 保安人員技術(shù)素養(yǎng)提升的路徑計(jì)劃
- 公共服務(wù)行業(yè)的品牌工作計(jì)劃
- 苗圃未來希望助力孩子成長計(jì)劃
- 加強(qiáng)跨國經(jīng)營管理提升全球競爭力計(jì)劃
- 弘揚(yáng)學(xué)生尊重勞動(dòng)的精神計(jì)劃
- 2025年地理信息大數(shù)據(jù)合作協(xié)議書
- 2025年中國橡膠行業(yè)市場運(yùn)行態(tài)勢、產(chǎn)業(yè)鏈全景及發(fā)展趨勢報(bào)告
- 七年級(jí)下冊《立方根》課件與練習(xí)
- 利用大數(shù)據(jù)分析預(yù)測用戶需求變化
- 2025年路面清潔裝備項(xiàng)目建議書
- 四新技術(shù)培訓(xùn)
- 人教版一年級(jí)數(shù)學(xué)2024版上冊期末測評(píng)(提優(yōu)卷一)(含答案)
- 浙江省杭州市2024年中考語文試卷(含答案)
- 碼頭安全生產(chǎn)知識(shí)培訓(xùn)
- 初中數(shù)學(xué)解《一元二次方程》100題含答案解析
- 種植二期手種植義齒II期手術(shù)護(hù)理配合流程
- 安全隱患舉報(bào)獎(jiǎng)勵(lì)制度
- 牛津書蟲系列1-6級(jí) 雙語 4B-03.金銀島中英對照
- 瀝青拌合站安裝專項(xiàng)施工方案
- 2024-2025學(xué)年深圳市南山區(qū)六年級(jí)數(shù)學(xué)第一學(xué)期期末學(xué)業(yè)水平測試試題含解析
- 2024-2030年中國免疫細(xì)胞存儲(chǔ)行業(yè)市場發(fā)展分析及競爭形勢與投資戰(zhàn)略研究報(bào)告
評(píng)論
0/150
提交評(píng)論