第81套
1.程式填空題
給定程式中,函式fun的功能是:將不帶頭結點的單向鏈表結點資料域中的資料從小到大排序,即若原鏈表從頭至尾結點資料域依次為:10、4、2、8、6,排序后,從頭至尾結點資料域依次為:2、4、6、8、10,
請在下劃線處填入正確的內容并將下劃線洗掉,使程式得出正確的結果,
注意:不得增行或刪行,也不得更改程式的結構!
#include <stdio.h> #include <stdlib.h> #define N 6 typedef struct node { int data; struct node *next; } NODE; void fun(NODE *h) { NODE *p, *q; int t; p = h; while (p) { /**********found**********/ q = __1__ ; /**********found**********/ while (__2__) { if (p->data > q->data) { t=p->data; p->data=https://www.cnblogs.com/cs-whut/p/q->data; q->data=https://www.cnblogs.com/cs-whut/p/t; } q = q->next; } /**********found**********/ p = __3__ ; } } NODE *creatlist(int a[]) { NODE *h,*p,*q; int i; h=NULL; for(i=0; i<N; i++) { q=(NODE *)malloc(sizeof(NODE)); q->data=https://www.cnblogs.com/cs-whut/p/a[i]; q->next = NULL; if (h == NULL) h = p = q; else { p->next = q; p = q; } } return h; } void outlist(NODE *h) { NODE *p; p=h; if (p==NULL) printf("The list is NULL!\n"); else { printf("\nHead "); do { printf("->%d", p->data); p=p->next; } while(p!=NULL); printf("->End\n"); } } int main() { NODE *head; int a[N]= {0, 10, 4, 2, 8, 6 }; head=creatlist(a); printf("\nThe original list:\n"); outlist(head); fun(head); printf("\nThe list after inverting :\n"); outlist(head); return 0; }
2.程式修改題
給定程式中,函式fun的功能是:判斷字符ch是否與字串str中的某個字符相同,若相同,什么也不做;若不同,則插在串的最后,
請改正函式fun中指定部位的錯誤,使它能得出正確的結果,
注意:不要改動main函式,不得增行或刪行,也不得更改程式的結構,
#include <stdio.h> #include <string.h> /**********found**********/ void fun(char str, char ch ) { while (*str && *str != ch) str++; /**********found**********/ if (*str == ch) { str [ 0 ] = ch; /**********found**********/ str[1] = '0'; } } int main() { char s[81], c ; printf( "\nPlease enter a string:\n" ); gets ( s ); printf("\n Please enter the character to search : "); c = getchar(); fun(s, c) ; printf( "\nThe result is %s\n", s); return 0; }
3.程式設計題
撰寫函式fun,它的功能是:把字串中的內容逆置,
例如,字串中原有的內容為:abcdefg,則呼叫該函式后,串中的內容為:gfedcba,
注意:請勿改動主函式main和其他函式中的任何內容,僅在函式fun的花括號中填入你撰寫的若干陳述句,
#include <string.h> #include <stdio.h> #define N 81 void NONO(void); void fun(char *s) { } int main() { char a[N]; printf("Enter a string: ");gets(a); printf("The original string is: ");puts(a); fun(a); printf("\n"); printf("The string after modified: "); puts(a); NONO( ); return 0; } void NONO(void) {/* 請在此函式內打開檔案,輸入測驗資料,呼叫 fun 函式,輸出資料,關閉檔案, */ int i ; char a[N] ; FILE *rf, *wf ; rf = fopen("in.dat", "r") ; wf = fopen("out.dat", "w") ; for(i = 0 ; i < 9 ; i++) { fscanf(rf, "%s", a) ; fun(a) ; fprintf(wf, "%s\n", a) ; } fclose(rf) ; fclose(wf) ; }
1.(1)p->next (2)q (3)p->next 2. void fun(char *str, char ch ) if (*str != ch) str[1] = '\0'; 3. void fun(char *s) { int i,j; char t; for (i=0,j=strlen(s)-1;i<j;i++,j--) { t=s[i]; s[i]=s[j]; s[j]=t; } }第81套參考答案
第82套
1.程式填空題
給定程式中,函式fun的功能是:在形參ss所指字串陣列中,將所有串長超過k的字串中右邊的字符洗掉,只保留左邊的k個字符,ss所指字串陣列中共有N個字串,且串長<M,
請在下劃線處填入正確的內容并將下劃線洗掉,使程式得出正確的結果,
注意:不得增行或刪行,也不得更改程式的結構!
#include <stdio.h> #include <string.h> #define N 5 #define M 10 /**********found**********/ void fun(char (*ss) __1__, int k) { int i=0 ; /**********found**********/ while(i< __2__) { /**********found**********/ ss[i][k]=__3__; i++; } } int main() { char x[N][M]={"Create","Modify","Sort", "skip","Delete"}; int i; printf("\nThe original string\n\n"); for(i=0;i<N;i++) puts(x[i]); printf("\n"); fun(x,4); printf("\nThe string after deleted :\n"); for(i=0; i<N; i++) puts(x[i]); printf("\n"); return 0; }
2.程式修改題
給定程式中,函式fun的功能是:先從鍵盤輸入一個3行3列矩陣的各個元素的值,然后輸出主對角線元素之和,
請改正函式fun中指定部位的錯誤,使它能得出正確的結果,
注意:不要改動main函式,不得增行或刪行,也不得更改程式的結構,
#include <stdio.h> void fun() { /*********found**********/ int a[3][3],sum; int i,j; for (i=0;i<3;i++) { for (j=0;j<3;j++) /*********found**********/ scanf("%d",a[i][j]); } for (i=0;i<3;i++) sum=sum+a[i][i]; printf("Sum=%d\n",sum); } int main() { fun(); return 0; }
3.程式設計題
撰寫函式fun,它的功能是:實作矩陣(3行3列)的轉置(即行列互換)
例如,輸入下面的矩陣
100 200 300
400 500 600
700 800 900
程式輸出
100 400 700
200 500 800
300 600 900
注意:請勿改動主函式main和其他函式中的任何內容,僅在函式fun的花括號中填入你撰寫的若干陳述句,
#include <stdio.h> void NONO(void); void fun(int array[3][3]) { } int main() { int i,j; int array[3][3]={{100,200,300}, {400,500,600}, {700,800,900}}; for (i=0;i<3;i++) { for (j=0;j<3;j++) printf("%7d",array[i][j]); printf("\n"); } fun(array); printf("Converted array:\n"); for (i=0;i<3;i++) { for (j=0;j<3;j++) printf("%7d",array[i][j]); printf("\n"); } NONO(); return 0; } void NONO(void) { /* 請在此函式內打開檔案,輸入測驗資料,呼叫 fun 函式,輸出資料,關閉檔案, */ int i,j, array[3][3]; FILE *rf, *wf ; rf = fopen("in.dat","r") ; wf = fopen("out.dat","w") ; for (i=0;i<3;i++) for (j=0;j<3;j++) fscanf(rf, "%d", &array[i][j]); fun(array); for (i=0;i<3;i++) { for (j=0;j<3;j++) fprintf(wf, "%7d", array[i][j]); fprintf(wf, "\n"); } fclose(rf) ; fclose(wf) ; }
1.(1)[M] (2)N (3)'\0' 2. int a[3][3],sum=0; scanf("%d",&a[i][j]); 3. void fun(int array[3][3]) { int i,j,t; for (i=1;i<3;i++) for (j=0;j<i;j++) { t=array[i][j]; array[i][j]=array[j][i]; array[j][i]=t; } }第82套參考答案
第83套
1.程式填空題
給定程式中,函式fun的功能是:找出形參s所指字串中出現頻度最高的字母(不區分大小寫),并統計其出現的次數,
例如,形參s所指字串為:abcAbsmaxless,程式執行后的輸出結果為:
letter ‘a’:3 times
letter ‘s’:3 times
請在下劃線處填入正確的內容并將下劃線洗掉,使程式得出正確的結果,
注意:不得增行或刪行,也不得更改程式的結構!
#include <stdio.h> #include <string.h> #include <ctype.h> void fun(char *s) { int k[26]={0},n,i,max=0; char ch; while(*s) { if( isalpha(*s) ) { /**********found**********/ ch=tolower(__1__); n=ch-'a'; /**********found**********/ k[n]+= __2__ ; } s++; /**********found**********/ if(max<k[n]) max= __3__ ; } printf("\nAfter count :\n"); for(i=0; i<26;i++) if (k[i]==max) printf("\nletter \'%c\': %d times\n",i+'a',k[i]); } int main() { char s[81]; printf("\nEnter a string:\n\n"); gets(s); fun(s); return 0; }
2.程式修改題
給定程式中,函式fun的功能是:將長整型數中每一位上為奇數的數依次取出,構成一個新數放在t中,高位仍在高位,低位仍在低位,
例如,當s中的數為:87653142時,t中的數為:7531,
請改正函式fun中指定部位的錯誤,使它能得出正確的結果,
注意:不要改動main函式,不得增行或刪行,也不得更改程式的結構,
#include <conio.h> #include <stdio.h> void fun (long s, long *t) { int d; long sl=1; /************found************/ t = 0; while ( s > 0) { d = s%10; /************found************/ if (d%2 == 0) { *t = d * sl + *t; sl *= 10; } s /= 10; } } int main() { long s, t; printf("\nPlease enter s:"); scanf("%ld", &s); fun(s, &t); printf("The result is: %ld\n", t); return 0; }
3.程式設計題
撰寫函式fun,它的功能是:計算并輸出給定陣列(長度為9)中每相鄰兩個元素之平均值的平方根之和,
例如,給定陣列中的9個元素依次為12.0、34.0、4.0、23.0、34.0、45.0、18.0、3.0、11.0,輸出應為:s=35.951014,
注意:請勿改動主函式main和其他函式中的任何內容,僅在函式fun的花括號中填入你撰寫的若干陳述句,
#include <stdio.h> #include <math.h> void NONO(void); double fun(double x[9]) { } int main() { double s,a[9]={12.0,34.0,4.0,23.0,34.0,45.0,18.0,3.0,11.0}; int i; printf("\nThe original data is :\n"); for(i=0;i<9;i++) printf("%6.1f",a[i]); printf("\n\n"); s=fun(a); printf("s=%f\n\n",s); NONO(); return 0; } void NONO(void) {/* 請在此函式內打開檔案,輸入測驗資料,呼叫 fun 函式,輸出資料,關閉檔案, */ FILE *rf, *wf ; int i, j ; double s, a[9] ; rf = fopen("in.dat", "r") ; wf = fopen("out.dat", "w") ; for(i = 0 ; i < 5 ; i++) { for(j = 0 ; j < 9 ; j++) fscanf(rf, "%lf", &a[j]) ; s = fun(a) ; fprintf(wf, "%lf\n", s) ; } fclose(rf) ; fclose(wf) ; }
1.(1)*s (2)1 (3)k[n] 2. *t = 0; if (d%2 != 0) 3. double fun(double x[9]) { double s=0.0; int i; for (i=0;i<9-1;i++) s+=sqrt(fabs((x[i]+x[i+1])/2)); return s; }第83套參考答案
第84套
1.程式填空題
給定程式中,函式fun的功能是:計算下列多項式的值

例如,當n=10時,輸出結果為:9.612558,
請在下劃線處填入正確的內容并將下劃線洗掉,使程式得出正確的結果,
注意:不得增行或刪行,也不得更改程式的結構!
#include <stdio.h> double fun(int n) { int i; double s, t; /**********found**********/ s=__1__; /**********found**********/ for(i=1; i<=__2__; i++) { t=2.0*i; /**********found**********/ s=s+(2.0*i-1)*(2.0*i+1)/__3__; } return s; } int main() { int n=-1; while(n<0) { printf("Please input(n>0): "); scanf("%d",&n); } printf("\nThe result is: %f\n",fun(n)); return 0; }
2.程式修改題
給定程式中,函式fun的功能是:統計子字串substr在字串str中出現的次數,
例如,若字串為aaaslkaaas,子字串為as,則應輸出2,
請改正函式fun中指定部位的錯誤,使它能得出正確的結果,
注意:不要改動main函式,不得增行或刪行,也不得更改程式的結構,
#include <stdio.h> int fun (char *str,char *substr) { int i,j,k,num=0; /************found************/ for(i = 0, str[i], i++) for(j=i,k=0;substr[k]==str[j];k++,j++) /************found************/ If(substr[k+1]=='\0') { num++; break; } return num; } int main() { char str[80],substr[80]; printf("Input a string:") ; gets(str); printf("Input a substring:") ; gets(substr); printf("%d\n",fun(str,substr)); return 0; }
3.程式設計題
撰寫函式fun,它的功能是:根據下列公式求π值(要求滿足精度eps,即某項小于eps時停止迭代),

例如,給定精度eps為0.0005時,應當輸出PI=3.140578,
注意:請勿改動主函式main和其他函式中的任何內容,僅在函式fun的花括號中填入你撰寫的若干陳述句,
#include <stdio.h> #include <math.h> void NONO(void); double fun ( double eps) { } int main() { double x; printf("Input eps:") ; scanf("%lf",&x); printf("\neps = %f, PI=%f\n", x, fun(x)); NONO(); return 0; } void NONO(void) {/* 本函式用于打開檔案,輸入資料,呼叫函式,輸出資料,關閉檔案, */ FILE *fp, *wf ; int i ; double x ; fp = fopen("in.dat","r") ; wf = fopen("out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(fp, "%lf", &x) ; fprintf(wf, "%f\n", fun(x)) ; } fclose(fp) ; fclose(wf) ; }
1.(1)0 (2)n (3)(t*t) 2. for(i = 0; str[i]; i++) if(substr[k+1]=='\0') 3. double fun ( double eps) { double s,t; int n=1; s=0.0; t=1.0; while( t>eps) { s+=t; t=t * n/(2*n+1); n++; } return (2*s); }第84套參考答案
第85套
1.程式填空題
給定程式中,通過定義學生結構體陣列,存盤了若干名學生的學號、姓名和3門課的成績,函式fun的功能是:將存放學生資料的結構體陣列,按照姓名的字典序(從小到大)排序,
請在下劃線處填入正確的內容并將下劃線洗掉,使程式得出正確的結果,
注意:不得增行或刪行,也不得更改程式的結構!
#include <stdio.h> #include <string.h> struct student { long sno; char name[10]; float score[3]; }; void fun(struct student a[], int n) { /**********found**********/ __1__ t; int i, j; /**********found**********/ for (i=0; i<__2__; i++) for (j=i+1; j<n; j++) /**********found**********/ if (strcmp(__3__) > 0) { t=a[i]; a[i]=a[j]; a[j]=t; } } int main() { struct student s[4]={{10001,"ZhangSan",95,80,88}, {10002,"LiSi", 85, 70, 78}, {10003,"CaoKai", 75, 60, 88}, {10004,"FangFang", 90, 82, 87}}; int i, j; printf("\n\nThe original data :\n\n"); for (j=0; j<4; j++) { printf("\nNo: %ld Name: %-8s Scores: ",s[j].sno, s[j].name); for (i=0; i<3; i++) printf("%6.2f ", s[j].score[i]); printf("\n"); } fun(s, 4); printf("\n\nThe data after sorting :\n\n"); for (j=0; j<4; j++) { printf("\nNo: %ld Name: %-8s Scores: ",s[j].sno, s[j].name); for (i=0; i<3; i++) printf("%6.2f ", s[j].score[i]); printf("\n"); } return 0; }
2.程式修改題
給定程式中,函式fun的功能是:計算n的5次方的值(規定n的值大于2,小于8),通過形參指標傳回主函式,并計算該值的低3位數字之和作為函式值回傳,
例如,7的5次方是16807,其低3位數字的和值是15,
請改正函式fun中指定部位的錯誤,使它能得出正確的結果,
注意:不要改動main函式,不得增行或刪行,也不得更改程式的結構,
#include <stdio.h> #include <math.h> int fun(int n ,int *value) { int d,s,i; /**************found**************/ d=0; s=1; for(i=1; i<=5; i++) d=d*n; *value=https://www.cnblogs.com/cs-whut/p/d; for(i=1; i<=3; i++) { s=s+d%10; /**************found**************/ s=s/10; } return s; } int main() { int n, sum, v; do { printf("\nEnter n( 2<n<8): "); scanf("%d",&n); } while(n<=2||n>=8); sum=fun( n,&v ); printf("\nThe result:\n value=https://www.cnblogs.com/cs-whut/p/%d sum=%d/n",v,sum); return 0; }
3.程式設計題
撰寫函式fun,它的功能是:計算當x<0.97時下列多項式的值,直到|S(n)-S(n-1)|<0.00001為止,

例如,在主函式中從鍵盤給x輸入0.21后,輸出為:S=1.100000,
注意:請勿改動主函式main和其他函式中的任何內容,僅在函式fun的花括號中填入你撰寫的若干陳述句,
#include <stdio.h> #include <math.h> void NONO(void); double fun(double x) { } int main() { double x,s; printf("Input x: "); scanf("%lf",&x); s=fun(x); printf("s=%f\n",s); NONO(); return 0; } void NONO(void) {/* 請在此函式內打開檔案,輸入測驗資料,呼叫 fun 函式,輸出資料,關閉檔案, */ FILE *rf, *wf ; int i ; double s, x ; rf = fopen("in.dat", "r") ; wf = fopen("out.dat", "w") ; for(i = 0 ; i < 10 ; i++) { fscanf(rf, "%lf", &x) ; s = fun(x) ; fprintf(wf, "%f\n", s) ; } fclose(rf) ; fclose(wf) ; }
1.(1)struct student (2)n-1 (3)a[i].name,a[j].name 2. d=1; s=0; d=d/10; 3. double fun(double x) { int i=0; double s=1,t=1; while (fabs(t)>0.000001) { t=t*(0.5-i)*x/(i+1); s+=t; i++; } return s; }第85套參考答案
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/528695.html
標籤:C
上一篇:如何跳過bs4標簽內的一些迭代?
下一篇:狂神說Go語言筆記—初識Go語言
