




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、程序填空 共2題 第1題/*-【程序填空】-功能:編程求某年第n天的日期。用數(shù)組表示月天數(shù)。-*/#include <stdio.h>#include <stdlib.h>main() int y,m,f,n; int a12=31,28,31,30,31,30,31,31,30,31,30,31; printf("y,n="); scanf("%d,%d",&y,&n); /*SPACE*/ f=y%4=0&&y%100!=0【|】y%400=0; /*SPACE*/ a1【+=】f; if(n&
2、lt;1|n>365+f) printf("error!n");exit(0); /*SPACE*/ for(m=1;m【>】am-1;n-=am-1,m+); printf("y=%d,m=%d,d=%dn",y,m,n);第2題 /*-【程序填空】-題目:下列程序從鍵盤輸入所需數(shù)據(jù),求出z的值并輸出,要求輸出結(jié)果保留2位小數(shù)。-*/#include <stdio.h>/*SPACE*/ 【#include<math.h>】 main() int x;double y,z;/*SPACE*/ scanf("
3、【%d%lf】",&x,&y); z=2*x*sqrt(y);/*SPACE*/ printf("z=【%lf】",z); 程序改錯(cuò) 共1題 第1題 /*- 【程序改錯(cuò)】-功能:將s所指字符串中的字母轉(zhuǎn)換為按字母序列的后續(xù)字母(但 Z轉(zhuǎn)換為A, z轉(zhuǎn)換為a),其它字符不變。-*/#include <stdio.h>#include <ctype.h>#include <conio.h>void fun (char *s)/函數(shù)定義 /*FOUND*/ while(*s!=0)/字符串結(jié)尾標(biāo)志為0 if(*s>
4、;='A' && *s <= 'Z' | *s >= 'a' && *s<='z') if(*s='Z') *s='A' else if(*s='z') *s='a' else /*FOUND*/ *s += 1;/s為字符指針,而*s為指針?biāo)傅淖址?/*FOUND*/ s+ main() char s80; printf("n Enter a string with length < 80. :nn
5、 "); gets(s); printf("n The string : nn "); puts(s); fun ( s );/函數(shù)調(diào)用 printf ("nn The Cords :nn "); puts(s);程序填空 共2題 第1題/*-【程序填空】-功能:計(jì)算圓周率的近似值。-*/#include <stdio.h>#include <math.h>main() int s,n; /*SPACE*/ double 【pi】,t; t=1;pi=0;n=1;s=1; /*SPACE*/ while(【fabs(t)
6、】>=2e-6)/fabs()為求絕對(duì)值函數(shù) pi+=t;n+=2;s=-s;t=s/n; /*SPACE*/ pi*=【4】; printf("pi=%.6fn",pi);第2題 /*-【程序填空】-功能:輸入一奇數(shù)n,打印由1->n*n構(gòu)成的魔方矩陣。魔方矩陣的 行列及對(duì)角線的和都相等。 魔方矩陣:8 1 6 3 5 7 4 9 2-*/#include <stdio.h>#include <stdlib.h>#define MAXSiZE 20void main(void) int matrixMAXSiZEMAXSiZE; int
7、 count; int row; int column; int n; char line100; printf("nOdd n Magic Square Generator"); printf("n="); printf("nnn Please -> "); gets(line); n = atoi(line); if (n > MAXSiZE) printf("n* ERROR * n should be <= %d", MAXSiZE); else if (n % 2 = 0) printf
8、("n* ERROR * n must be an odd integer"); else row = 0; column = n/2; for (count = 1; count <= n*n; count+) matrixrowcolumn = count; /*SPACE*/ if (【count/n】 = 0) row+; else /*SPACE*/ row= (row = 【0】) ? n - 1 : row - 1; /*SPACE*/ column = (column = 【n-1】) ? 0 : column + 1; printf("nn
9、Magic Square of n %d :nn", n); for (row = 0; row < n; row+) for (column = 0; column < n; column+) printf("%4d", matrixrowcolumn); printf("n"); 程序改錯(cuò) 共1題/*- 【程序改錯(cuò)】-功能:求1到10的階乘的和。-*/#include <stdio.h>float fac(int n);/函數(shù)聲明main() int i; float s=0; float fac(int n);/函
10、數(shù)聲明應(yīng)放在主函數(shù)之前,這句放錯(cuò)位置了,刪了吧,也可以不改,可以運(yùn)行,但良好的習(xí)慣就是改 /*FOUND*/ for(i=1;i<10;i+) /*FOUND*/ s+=fac(i);/函數(shù)調(diào)用 printf("%fn",s);float fac(int n)/函數(shù)定義/*FOUND*/ float y=1;/int改為float,否則會(huì)造成數(shù)據(jù)丟失,當(dāng)然也可以不改,畢竟你們沒學(xué)到 int i; for(i=1 ;i<=n;i+) y=y*i; /*FOUND*/ return y;程序填空 共2題 第1題/*-【程序填空】-功能:刪除字符串中的指定字符,字符串
11、和要?jiǎng)h除的字符均由鍵盤 輸入。-*/#include <stdio.h>main() char str80,ch; int i,k=0; /*SPACE*/ gets(【str】);/輸入字符串 放入str ch=getchar(); /*SPACE*/ for(i=0;【stri】;i+)/循環(huán)到字符串結(jié)束為止 if(stri!=ch) /假如沒找到就將原字符賦值過去 找到要?jiǎng)h除的就跳過繼續(xù)找 /*SPACE*/ 【strk=stri】;/在同一個(gè)數(shù)組中操作,后面的字符覆蓋了前面要?jiǎng)h除的位置 k+; /*SPACE*/ 【strk=0】;/在新字符串結(jié)尾處加結(jié)束符 puts(st
12、r);/輸出 第2題/*-【程序填空】-功能:輸入一個(gè)整數(shù),計(jì)算它可能是哪兩個(gè)整數(shù)的平方和,并打印 結(jié)果數(shù)據(jù)。 如:34是5和3或3和5的平方和。-*/#include <stdio.h> /* for i/O functions */#include <stdlib.h> /* for atoi() */#include <math.h> /* for sqrt() */void main(void) int given; /* the given number */ int row, column; /* row and column indicator
13、s*/ int count; /* number of solutions */ char line100; printf("nRepresenting a Given Number as the Sum of Two Squares"); printf("n=n"); printf("nAn integer Please -> "); gets(line); given = atoi(line); printf("nCount X Y"); printf("n- - -"); row =
14、 1; /* starts from far enough */ column = (int) (sqrt(double) given) + 0.5); count = 0; /* so solution yet */ while (row <= given && column > 0) /* scan down. */ if (row*row + column*column = given) /*SPACE*/ 【count+】; printf("n%5d%7d%7d", count, row, column); row+; column-;
15、else if (row*row + column*column > given) /*SPACE*/ 【column-】; else /*SPACE*/ 【row+】; if (count = 0) printf("nnSorry, NO ANSWER found."); else printf("nnThere are %d possible answers.",count);程序改錯(cuò) 共1題 第1題 /*- 【程序改錯(cuò)】-功能:計(jì)算并輸出k以內(nèi)最大的10個(gè)能被13或17整除的自然數(shù)之和。 k的值由主函數(shù)傳入。例如:若k的值為500,則函數(shù)值為
16、4622。-*/#include <stdio.h>int fun(int k) int m=0,mc=0; /*FOUND*/ while (k>=2)&&(mc<10) /*FOUND*/ if(k%13=0)|(k%17=0) m=m+k; mc+; /*FOUND*/ k-; /*FOUND*/ return m;void main() printf("%dn",fun(500);程序填空 共2題 第1題 /*-【程序填空】-功能:當(dāng)輸入“2,5”的時(shí)候輸出為“2 5 5”-*/#include <stdio.h>
17、#define max 100main() int fmax,i,j,k,m; scanf("%d,%d",&k,&m); /*SPACE*/ for(i=0;i<=【2】;i+) fi=0; /*SPACE*/ f【k-1】=1; for(i=k;i<=m;i+) /*SPACE*/ for(j=i-k;j<=i-1;j+) fi【=1+】fj; printf("%d%10d%10dn",k,m,fm);第2題 /*-【程序填空】-功能:識(shí)別輸入的字符串,每個(gè)單詞輸出一行-*/#include <stdio.h&
18、gt;#include <string.h>void main() int c; int inspace; /*SPACE*/ 【inspace=0】; while(c = getchar() != 'n') if(c = ' ' | c = 't' | c = 'n') /*SPACE*/ if(【inspace=0】) inspace = 1; putchar('n'); else inspace = 0; /*SPACE*/ 【putchar(c)】; 程序改錯(cuò) 共1題 第1題 /*- 【程序改錯(cuò)
19、】-功能:用選擇法對(duì)數(shù)組中的n個(gè)元素按從小到大的順序進(jìn)行排序。-*/#include <stdio.h>#define N 20 void fun(int a, int n) int i, j, t, p; for (j = 0 ;j < n-1 ;j+) /*FOUND*/ p = j; for (i = j;i < n; i+) /*FOUND*/ if(ai >ap) /*FOUND*/ p=i; t = ap ; ap = aj ; aj = t; main() int aN=9,6,8,3,-1,i, m = 5; printf("排序前的數(shù)據(jù)
20、:") ; for(i = 0;i < m;i+) printf("%d ",ai); printf("n"); fun(a,m); printf("排序后的數(shù)據(jù):") ; for(i = 0;i < m;i+) printf("%d ",ai); printf("n");程序填空 共2題 第1題 /*-【程序填空】-功能:產(chǎn)生10個(gè)30,90區(qū)間上的隨機(jī)整數(shù),然后對(duì)其用選擇法 進(jìn)行由小到大的排序。-*/#include <stdio.h>#include<
21、;stdlib.h>main() /*SPACE*/ int t; int i,j,k; int a10; for(i=0;i<10;i+) ai=rand()%61+30; for(i=0;i<9;i+) /*SPACE*/ k=i; for(j=i+1;j<10;j+) /*SPACE*/ if(ak>aj) k=j; if(k!=i) t=ak; ak=ai; ai=t; /*SPACE*/ for(i=0;i<10;i+ ) printf("%5d",ai); printf("n");第2題 /*-【程序填空】
22、-功能:輸入一正整數(shù)n、打印1-n能夠組成的所有自然數(shù)集合 (包含空集)。-*/#include <stdio.h>#include <stdlib.h>#define MAXSiZE 20#define LOOP 1void main(void) int setMAXSiZE; int n, i; int position; char line100; printf("nAll Possible Subsets Generation by Lexical Order"); printf("n="); printf("n
23、nNumber of Elements in the Set -> "); gets(line); n = atoi(line); printf("n"); position = 0; setposition = 1; while (LOOP) /*SPACE*/ printf("n%d", 【?】); for (i = 1; i <= position; i+) printf(",%d", seti); printf(""); if (setposition < n) /*SPACE*
24、/ set【?】 = setposition + 1; position+; else if (position != 0) set-position+; else /*SPACE*/ 【?】; 程序改錯(cuò) 第1題 /*- 【程序改錯(cuò)】-功能:求出以下分?jǐn)?shù)序列的前n項(xiàng)之和。和值通過函數(shù)值返回main 函數(shù)。 2/1+3/2+5/3+8/5+13/8+21/13 例如:若n = 5,則應(yīng)輸出:8.391667。-*/#include <conio.h>#include <stdio.h> /*FOUND*/fun ( int n ) int a, b, c, k; doub
25、le s; s = 0.0; a = 2; b = 1; for ( k = 1; k <= n; k+ ) /*FOUND*/ s = (double)a / b; c = a; a = a + b; b = c; /*FOUND*/ return c;main( ) int n = 5; printf( "nThe value of function is: %lfn", fun ( n ) );程序填空 共2題 第1題 /*-【程序填空】-功能:輸出結(jié)果為:* * * * * * * * * * * * * * * * * * * * -*/#include &
26、lt;stdio.h>main() /*SPACE*/ static char 【?】='*','*','*','*','*' int i,j,k; char space=' ' for(i=0;i<5;i+) printf("n"); for(j=1;j<=3*i;j+) /*SPACE*/ printf("%1c",【?】); /*SPACE*/ for(k=0;k<【?】;k+) printf("%3c",ak
27、); printf("n");第2題 /*-【程序填空】-功能:給出一個(gè)正整數(shù),找到一組連續(xù)的數(shù),使之累加和等于給 定的正整數(shù)。輸出存在多少組這樣連續(xù)的數(shù),及每組的左 右邊界。例如:15=1+2+3+4+5 15=4+5+6 15=7+8 所以結(jié)果有3組值分別是1->5, 4->6, 7->8-*/#include <stdio.h>#include <stdlib.h>void main(void) long left, right; long sum; long GiVEN; int count = 0; char line10
28、0; printf("nConsecutive sum to a fixed given number"); printf("n=n"); printf("nYour number (> 0) please -> "); gets(line); GiVEN = atol(line); for (sum = 0, right = 1; sum < GiVEN; sum += right, right+) ; for (left = 1, right-; left <= GiVEN/2; ) if (sum >
29、; GiVEN) sum -= left; /*SPACE*/ 【?】; else if (sum = GiVEN) printf("n%ld = sum from %ld to %ld", GiVEN, left, right); /*SPACE*/ 【?】; /*SPACE*/ 【?】; sum += right; if (count > 0) printf("nnThere are %d solutions in total.", count); else printf("nnSorry, there is NO solution
30、at all.");程序改錯(cuò) 第1題 /*- 【程序改錯(cuò)】-功能:編寫函數(shù)fun計(jì)算下列分段函數(shù)的值: x*20 x<0且x-3 f(x)= sin(x) 0x<10且x2及x3 x*x+x-1 其它-*/#include <math.h>#include <stdio.h>double fun(double x) /*FOUND*/ double y /*FOUND*/ if (x<0 | x!=-3.0) y=x*20; else if(x>=0 && x<10.0 && x!=2.0 &
31、;& x!=3.0) y=sin(x); else y=x*x+x-1; /*FOUND*/ return x;main() double x,f; printf("input x="); scanf("%f",&x); f=fun(x); printf("x=%f,f(x)=%fn",x,f);程序填空 共2題 第1題 /*-【程序填空】-功能:有n個(gè)整數(shù),使其前面各數(shù)順序向后移m個(gè)位置,最后m個(gè)數(shù) 變成最前面的m個(gè)數(shù)-*/#include <stdio.h>/*SPACE*/move(【?】)int n
32、,m,array20; int *p,array_end; /*SPACE*/ array_end=*(【?】); for(p=array+n-1;p>array;p-) /*SPACE*/ *p=*(【?】); *array=array_end; m-; if(m>0) move(array,n,m);main() int number20,n,m,i; printf("the total numbers is:"); scanf("%d",&n); printf("back m:"); scanf("
33、%d",&m); for(i=0;i<n-1;i+) scanf("%d,",&numberi); scanf("%d",&numbern-1); /*SPACE*/ move(【?】); for(i=0;i<n-1;i+) printf("%d,",numberi); printf("%d",numbern-1);第2題 /*-【程序填空】-功能:打印出如下圖案(菱形) * * * * * *-*/#include <stdio.h>main() int i,j,k; /*SPACE*/ for(i=0;【?】;i+) for(j=0;j<=4-i;j+) printf(" "); /*SPACE*/ for(k=1;k<=【?】;k+) printf("*"); printf("n"); /*SPACE*/ for(【?】;j<3;j+) for(k=0;k<j+3;k+) printf(" "); for(k=0;k<
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(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ǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 浙江省金華市2025年八年級(jí)下學(xué)期語文期末試卷及答案
- 班級(jí)歲月軌跡
- 2025年中國螺旋板式煤氣冷卻器市場調(diào)查研究報(bào)告
- 2025年中國草除靈原藥項(xiàng)目投資可行性研究報(bào)告
- 2025年中國自行車袋數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 2025年中國肩章市場調(diào)查研究報(bào)告
- 2025年中國美工專用色瓶套裝市場調(diào)查研究報(bào)告
- 2025年中國絨繡工藝品制作項(xiàng)目投資可行性研究報(bào)告
- 2025年中國紅瓷花瓶數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 2025年中國簡易海綿磨球機(jī)市場調(diào)查研究報(bào)告
- 敦煌的藝術(shù)智慧樹知到期末考試答案章節(jié)答案2024年北京大學(xué)
- 社區(qū)飲水機(jī)占地合同
- 江蘇省南京市鼓樓區(qū)2023-2024學(xué)年八年級(jí)下學(xué)期期末考試物理試題
- (高清版)JTG 3363-2019 公路橋涵地基與基礎(chǔ)設(shè)計(jì)規(guī)范
- 第10課和諧校園共同維護(hù)(課件)-【中職專用】高一思想政治《心理健康與職業(yè)生涯》(高教版2023·基礎(chǔ)模塊)
- 2024年04月江蘇省農(nóng)業(yè)農(nóng)村廳直屬事業(yè)單位2024年公開招考工作人員筆試歷年高頻考題摘選后附答案詳解
- 傷口造口進(jìn)修匯報(bào)護(hù)理
- 檔案整理及數(shù)字化服務(wù)售后服務(wù)方案
- 2024年一年級(jí)《體育與健康》全冊(cè)教案
- 臂叢神經(jīng)損傷康復(fù)護(hù)理
- 糜爛性胃炎的護(hù)理查房
評(píng)論
0/150
提交評(píng)論