《VC實驗教程答案》word版_第1頁
《VC實驗教程答案》word版_第2頁
《VC實驗教程答案》word版_第3頁
《VC實驗教程答案》word版_第4頁
《VC實驗教程答案》word版_第5頁
已閱讀5頁,還剩61頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、實驗一熟悉Microsft Visual C+ 6.0開發環境四思考題#include void main() int a,b,c; coutab; /輸入兩個數據到變量a、b中 c=a*b; /求乘積存入c couta*b=cendl; /輸出結果 實驗二輸入/輸出與順序結構三 實驗內容1. 閱讀程序,寫出運行結果。 i+j=15i*j=50 a=9 b=5 2. 程序填空 k=i+j i+j= a=c charctASCII=a 3. 程序改錯#include void main() double r,s,l; coutr; s=3.1416*r*r; l=2.0*3.1416*r; co

2、utS=sendl; coutL=lendl; 4. 編程題 輸入華氏溫度F,計算輸出對應的攝氏溫度。由華氏溫度F求攝氏溫度c的公式為:#include void main() double f,c; coutf; c=(f-32)*5/9; /或c=5.0/9*(f-32); coutC=cendl; 輸入學生的語文、數學、英語、物理4門課程的成績,計算該學生的總成績和平均成績并輸出。#include void main() double eng, chin,math,phy,sum,aver; coutengchinmathphy; /輸入成績 sum=eng+chin+math+phy;

3、 /計算總成績 aver=sum/4; /計算平均分 coutSum=sumendltAverage=averendl; /輸出 編寫程序,從鍵盤輸入一個大寫英文字母,輸出對應的小寫字母。#include void main()char c1,c2;coutc1;c2=c1+32;coutc1=c1tc2=c2endl; 實驗三選擇結構程序設計三 實驗內容1.選擇題 C B D C C C D 2. -4 4 5 99 2,1 1 3. 編程題 由鍵盤輸入三個字符,輸出其中的最大者。【源程序】#include void main() char x,max; coutx; max=x; cinx

4、; if (xmax) max=x; cinx; if (xmax) max=x; coutmax = maxendl; 輸入三角形三邊的長,求三角形的面積。若輸入的三個邊能構成三角形,則計算其面積并輸出;否則輸出提示信息。【源程序】/參見教材P44例3.15#include#include void main() double a,b,c,s,area; coutabc; if (a+b=c|a+c=b|b+c=a)coutcant be a triangle!n;else s=(a+b+c)/2; area=sqrt(s*(s-a)*(s-b)*(s-c);coutarea=area0)

5、-1 (x0) 【源程序】#include void main() int x,y; coutx; if (x0) y=1; else if (x=0) y=0; else y=-1; couty=yendl; 計算獎金。設企業利潤為L,當企業利潤L不超過5000元時,獎金為利潤的1.5%,當5000L10000元時,超過5000元部分獎金為2%(5000元以下仍按1.5%);當10000L20000元,除10000以下的按上述方法計算外,超過10000元部分按2.5%計算獎金;如果20000L50000元,超過20000元部分按3%計算獎金;當50000L100000元時,超過50000元部

6、分按3.5%計算獎金;當L超過100000元時,超過100000元部分按4%計算獎金。由鍵盤輸入L的值,編程計算相應的獎金并輸出。【源程序】#includevoid main() double L,S; coutL; if(L5000) S=L*0.015; else if(L10000) S=75+(L-5000)*0.02; else if(L20000) S=175+(L-10000)*0.025; else if(L50000) S=175+250+(L-20000)*0.03; else if(L100000) S=175+250+900+(L-50000)*0.035; else

7、S=175+250+900+1750+(L-100000)*0.04; coutS=Sendl; 輸入年齡,輸出所處人群:9歲以下為兒童,輸出A;1019為少年,輸出B;2029為青年,輸出C;3049為中年,輸出D;50以上為老年,輸出E。【源程序】#include void main() int age; coutage; switch(age/10) case 0:coutA-兒童n;break; case 1:coutB-少年n;break; case 2:coutC-青年n;break; case 3: case 4:coutD-中年n;break; default:coutE-老年

8、n;break; 有如下函數:0t11t22t33t4 由鍵盤輸入t值,計算S的值。【源程序】/方法一#include void main()double t,s;coutt; if(t0&t4)if(t1)s=t*t;else if(t2) s=t*t-1;else if(t3)s=t*t-2*t+1;else s=t*t+4*t-17;couts=sendl;elsecoutError! t cant be less than 0 or more than 4!n; /方法二#include void main()double t;coutt; if(t=0)couterror, t ca

9、nt be less than 0!n;else if(t1)couts=t*tendl;else if(t2) couts=t*t-1endl;else if(t3)couts=t*t-2*t+1endl;else if(t4)couts=t*t+4*t-17endl;elsecouterror, t cant be more than 4!n; /方法三#include void main()double t,s;coutt; if(t=0)couterror, t cant be less than 0!n;else if(t1)s=t*t;couts=sendl;else if(t2)

10、 s=t*t-1;couts=sendl;else if(t3)s=t*t-2*t+1;couts=sendl;else if(t4)s=t*t+4*t-17;couts=sendl;elsecouterror, t cant be more than 4!n; 實驗四 循環結構程序設計 三 實驗內容1選擇題 下面程序的運行結果是_ D _。#include 2閱讀程序,寫出運行結果。下面程序的運行結果是_0918273645_。 下面程序的運行結果是_a=4_。 下面程序的運行結果是_n=4_。3程序填空 下面程序的功能是依次顯示100,80,60,40,20這5個數,請填空。#includ

11、e void main() int i; for(i=100;_i=20_;_i-=20_) coutit; coutendl; 下面程序的功能是計算xn,請填空。#include void main() int n,x; coutxn; double y=1; for(int i=0;i_n_;i+) _ y*=x;_; coutyendl; 下面程序的功能是計算1-3+5-7+-99+101的值,請填空。#include void main() int i,t,s=0,sign=1; for(i=1;i=101;i+=2) _t=i*sign_; s+=t; sign=-sign_; co

12、uts=sendl; * * * 下面程序的功能是輸出以下形式的金字塔圖案:#include void main() for(int i=1;i=4;i+) for(int j=1;j=_4-i_;j+) cout ; for(j=1;j=_2*i-1_;j+) cout*; coutendl; 4編程題 輸入n,求1+2+3+n的和。 #includevoid main() int i,n; double sum=0; cinn; for(i=1;i=n;i+) sum+=i; cout1+2+3+.+n=sumendl; 輸入若干個整數,求它們的和,遇到-999時結束輸入。 #includ

13、evoid main() int n; double sum=0; cinn; for(;n!=-999;) /while(n!=-999) sum+=n; cinn; coutsum=sumendl; 輸入一整數,輸出各位數字之和。如輸入6228,則輸出6+2+2+8的和為18。#includevoid main() double s=0; int n; cinn; while(n!=0) s+=n%10; n=n/10; couts=sendl; 輸入一實數x和一整數n,求x+x2+x3+xn的值。#include void main() int i,j,n; double x,sum=0

14、,p; cinnx; for(i=1;i=n;i+) p=1.; for(j=1;j=i;j+) p*=x; sum+=p; coutx=xtn=nendl; coutsum=sumendl; 求2!+4!+6!+16!。#includevoid main() int i,j; double sum=0,p; for(i=2;i=16;i+=2) p=1; for(j=1;j=i;j+) p*=j; sum+=p; cout2!+4!+6!+.+16!=sumendl; * * * 輸入兩個整數n和m,打印n行星號,每行m個星號。如果輸入的n和m的值為4 7,則輸出為:#include voi

15、d main() int i,j,n,m; cinnm; for(i=0;in;i+) for(j=0;ji;j+) cout ; for(j=0;jm;j+) cout*; coutendl; 求1n+3n+5n+7n+(2m-1)n,其中m和n的值從鍵盤輸入。#include void main() int i,j,n,m,sum=0,p; cinnm; for(i=1;i=2*m-1;i+=2) p=1.; for(j=1;j=n;j+) p*=i; sum+=p; coutm=mtn=nendl; coutsum=sumendl; 1程序填空 以下程序的功能是計算:s=1+12+123

16、+1234+12345。請填空。 t=10*t+i s=s+t 下面程序的功能是輸出符合條件的三位整數:它是完全平方數,又有兩位數字相同,并且統計個數,請填空。(i-n1*100)/10或(i/10)%10num+j+2編程(1)輸入10個字符,輸出其中的最大者。#includevoid main() char ch,maxchar; coutch; maxchar=ch; for(int i=1;ich; if(chmaxchar)maxchar=ch; coutmaxchar=maxcharendl;(2)一個球從100m高度自由落下,每次落地后反彈回原來高度的一半,再落下,再反彈。求它在

17、第10次落地時,共經過多少米?第10次反彈多高?分析:共經過: 100*(1+1/2+1/4+1/8-+1/1024) 米第10次:100/1024米#includevoid main() double s=1,t=1,sum,t10; int i; for(i=1;i=10;i+)t=2*t;s=s+1/t;t10=100/t;sum=100*s;coutsum=sumtt10=t10endl; (3)用下列泰勒級數求sinx的近似值,x的值從鍵盤輸入,精度要求為10-6。 #include#includevoid main() int sign=1,n=1; double x=3.0,fe

18、nzi=x,fenmu=1.0,equo=1,sum=x; while(fabs(equo)=1e-6) fenzi*=x*x; fenmu*=(2*n)*(2*n+1); sign*=-1; equo=sign*fenzi/fenmu; sum+=equo; n+; coutsin x=sumendl;(4)編寫程序,對輸入的一批整數統計出正數的個數、負數的個數、奇數的個數、偶數的個數,要求所統計的整數由鍵盤輸入,以0作為輸入數據結束的標志。#includevoid main() int a=0,b=0,c=0,d=0,x; cinx; while(x!=0) if(x0)a+=1; if(

19、xx; cout正數個數=aendl; cout負數個數=bendl; cout奇數個數=cendl; cout偶數個數=dendl;(5)用牛頓迭代法求方程2x3-4x2+3x6=0在1.5附近的根,精度要求為10-6。#include#includevoid main() double x1,x2=1.5,y1,y2; cout x1 x2 yn; do x1=x2; y1=2*x1*x1*x1-4*x1*x1+3*x1-6; y2=6*x1*x1-8*x1+3; x2=x1-y1/y2; couttx1tx2ty11e-6); coutx=x1endl;(6)輸出這樣的三位整數:這些三位

20、數的個、十、百位上的數字均不相同,并且能被11整除。#includevoid main() int i,j,k,n=0; for(i=1;i10;i+) for(j=0;j10;j+) for(k=0;k10;k+) if(i=j|j=k|k=i) continue; else if(i*100+j*10+k)%11=0) cout+n; cout:i*100+j*10+kt; (7)輸入兩個正整數m和n,求其最大公約數和最小公倍數。#includevoid main() int a,b,num1,num2,temp; coutnum1num2; if(num1num2) temp=num1;

21、 num1=num2; num2=temp; a=num1,b=num2; while(b!=0) temp=a%b; a=b; b=temp; cout最大公約數為:aendl; cout最小公倍數為:num1*num2/aendl;實驗六/* * 輸入10個學生的成績,求其平均值,輸出最高成績,并統計低于平均值的人數。 * 注: LT是小于的意思,less than */#include const double LOWER = - 10000;void main()double score10;double highestScore = LOWER;double average = 0;

22、double numLTaverage = 0;/輸入、求最高分、求總分for (int i = 0; i 10 ; + i)cout Please input the score ( i + 1 scorei;if ( highestScore scorei ) highestScore = scorei;average += scorei;average /= 10;/求成績低于平均分的人數for ( i = 0; i 10; + i)if ( scorei average ) + numLTaverage ;cout The average score is average endl;c

23、out The highest score is highestScore endl;cout The number of LT average is numLTaverage endl;/* * 分別用冒泡法和選擇法對輸入的10個整數按由大到小排序。 * 冒泡法參見課本第四章課后作業第四題 */#include void main()int myArray10;int outer, inner;int imax;for ( int i = 0; i 10 ; + i )cout myArrayi;for ( outer = 0 ; outer 10 ; + outer)/在下標位outer到

24、9之間的元素中尋找最大值imax = outer ;for ( inner = outer + 1; inner 10 ; + inner)if ( myArrayimax myArrayinner ) imax = inner;/將最大值與下標為outer的元素交換int temp = myArrayouter;myArrayouter = myArrayimax;myArrayimax = temp;/輸出for ( i = 0; i 10 ; + i )cout myArrayi ;cout endl;/* * 使用折半查找法,在給定的數組中查找某個數據。 */#include cons

25、t int N = 10;void main()int myArrayN = 1, 5, 8, 13, 16, 34, 67, 78, 90, 100;int iSearch;cout iSearch;int low = 0;int high = N - 1;int mid;/開始二分查找while ( low = high )mid = ( low + high ) / 2;if ( myArraymid = iSearch ) break;else if ( myArraymid iSearch )low = mid + 1;elsehigh = mid - 1;/判斷是否找到if ( m

26、yArraymid = iSearch )cout We have found the number. endl;elsecout We havnt found the number. endl;/* * 按楊輝三角形的規律打印以下的數據(要求只打印出10行)。 * 1 * 1 1 * 1 2 1 * 1 3 3 1 * 1 4 6 4 1 * 1 5 10 10 5 1 * */#include void main()int yangHui1010;yangHui00 = yangHui10 = yangHui11 = 1;for ( int i = 2; i 10 ; + i )yangH

27、uii0 = yangHuiii = 1;for ( int j = 1 ; j i ; + j )yangHuiij = yangHuii - 1j + yangHuii - 1j - 1;for ( i = 0 ; i 10 ; + i )for (int j = 0; j = i ; + j )cout yangHuiij t;cout endl;/* * 編寫程序統計某班英語、語文、數學3門課程的成績, * 學生人數與成績由鍵盤輸入,要求統計出每門課程全班 * 的總成績和平均成績以及每個學生三門課程的總成績和 * 平均成績。 */#include void main()/由用戶輸入學生

28、人數int numStu;cout numStu;/根據用戶輸入的人數建立數組,其中0-2列為三門課成績,最后一列是總分。/最后添加一行用來存儲總分。int (*p)4;p = new intnumStu + 14;/將總分置0pnumStu0 = pnumStu1 = pnumStu2 = 0;for ( int i = 0 ; i numStu ; + i )/將每個人的總分置0pi3 = 0;cout ID is i + 1 :n;/輸入英語成績cout pi0;pi3 += pi0;pnumStu0 += pi0;/輸入物理成績cout pi1;pi3 += pi1;pnumStu1

29、+= pi1;/輸入英語成績cout pi2;pi3 += pi2;pnumStu2 += pi2;/輸出for ( i = 0 ; i numStu ; + i )cout ID i + 1 :n;cout The sum is pi3 ;cout .tThe average is pi3/3.0 ;cout endl;cout Eng: sum= pnumStu0 ,average= pnumStu0/double(numStu);cout nPhy: sum= pnumStu1 ,average= pnumStu1/double(numStu);cout nMat: sum= pnumS

30、tu2 ,average= pnumStu2/double(numStu);delete p;/* * 編寫程序求對矩陣進行轉置,即將元素的行列位置交換。 */#include void main()int myMatrix44;/輸入for ( int i = 0; i 4; + i )for ( int j = 0; j 4; + j)cout ( i + 1 , j + 1 myMatrixij;/輸出轉置前的數組cout Before exchange:n;for ( i = 0; i 4; + i )for ( int j = 0; j 4; + j)cout myMatrixij

31、t;cout endl;/轉置for ( i = 0 ; i 4 ; + i)for ( int j = 0 ; j i ; + j)int temp = myMatrixij;myMatrixij = myMatrixji;myMatrixji = temp;/輸出轉置后的數組cout After exchange:n;for ( i = 0; i 4; + i )for ( int j = 0; j 4; + j)cout myMatrixij t;cout endl;/* * 編寫程序求兩個矩陣的乘積,若矩陣ANM與BMK相乘, *則得到矩陣C,其行列數為NK。注意A的列數與B的行數相同

32、 *,才可以進行乘法操作。 */#include const int N = 3;const int M = 4;const int K = 5;void main()/定義數組int aNM,bMK,cNK;/輸入數組Acout Matrix A:n;for ( int i = 0; i N; + i)for ( int j = 0; j M; + j)cout ( i + 1 , j + 1 )/;cout ( N , M aij;/輸入數組Bcout Matrix B:n;for ( i = 0; i M; + i)for ( int j = 0; j K; + j)cout ( i +

33、 1 , j + 1 )/;cout ( M , K bij;/計算C,并輸出cout Matrix C=AXB:n;for ( i = 0; i N; + i)for ( int j = 0; j K; + j)cij = 0;for (int k = 0 ; k M ; + k)cij += aik * bkj;cout cij t;cout endl; 實驗七 數組與指針(一) 三 實驗內容1 選擇題B D D D D C 2分析以下程序,寫出程序的運行結果,并上機調試驗證。 下面程序的運行結果為_ C+_ 下面程序的運行結果為_C+ Program _ 下面程序的運行結果為 下面程序的

34、運行結果為_i=10_ 下面程序的運行結果為*p=1*(p+3)=12_ 下面程序的運行結果為min=-8max=100_ 下面程序的運行結果為_xbcdBCD_3程序填空 下面程序的功能是輸出: p+ p str1i!=0 str2j!=0 str1i=str2j; t=pp=qq=t4編寫程序并上機調試運行 編寫程序,輸入5個字符串,輸出其中最大者。要求使用二維字符數組及字符串函數。#include #includeconst int N=3;void main() char aN20; int i,max=0; for(i=0;iN;i+) cin.getline(ai,20); for

35、(i=1;i0) strcpy(amax,ai); coutamaxendl; 編寫程序,將一個字符串中的數字字符都刪除。#include void main() char a20; int i=0,j=0; cout”Please input the characters: ”; cin.getline(a,20); for(i=0;ai!=0;i+) if(ai9) aj+=ai; aj=0; coutaendl; 編寫程序,輸入一行字符,統計其中有多少個單詞,單詞之間用一個或多個空格分隔。#include void main() char a100; int i,num=0; coutP

36、lease input the characters:n; cin.getline(a,100); for(i=0;ai!=0;i+) while(ai= ) i+; num+; while(ai!= ) i+; coutThe number of the words are: num; 四 問題討論1字符數組的輸入、輸出有幾種方法?2字符串與字符數組有何相同與不同之處?3數組元素及其地址有幾種表示方法? 實驗八 數組與指針(二) 三實驗內容1選擇題B C A A A2分析以下程序,寫出程序的運行結果,并上機調試驗證結果 下面程序的運行結果為_ 12_ 下面程序的運行結果為 hellogood

37、 morninghow are you 下面程序的運行結果為 1 2 3 4 5 下面程序的運行結果為_c=b 下面程序的運行結果為 a=10,ref=10 a=100,ref=1003程序填空 pi=chi p=new charn; delete p; a k+1 0 strk4編寫程序并上機調試運行 輸入若干個字符串,實現用英文字典排列順序由大到小排列。要求使用指針數組,字符串由鍵盤輸入。#includeiostream.h#includestring.hconst int N=5;const int M=20; void main() char sNM, *pN, *t = NULL;

38、int i, j; for(i = 0; i N; i+) pi = si; for(i = 0; i N; i+) cin.getline(pi, M); for(i = 0; i N - 1; i+) for(j = 0; j N - 1 - i; j+) if(strcmp(pj, pj + 1) 0) t = pj; pj = pj + 1; pj + 1 = t; for(i = 0; i N; i+) coutpiendl; 用二級指針對任一二維整型數組的元素求和。#includeiostream.hconst int M = 2;const int N = 3; void mai

39、n() int aMN, *pM, *pp=p; int i, j, sum = 0; for(i = 0; i M; i+) pi = ai; for(i = 0; i M; i+) for(j = 0; j ppij; sum += ppij; coutnsum = sum; 編寫程序,當輸入17(表示星期幾)時,顯示相應的星期的英文名稱,輸入其它整數時則顯示錯誤信息。#includeiostream.hconst int M = 2;const int N = 3; void main() char *p7 = Monday, Tuesday, Wednesday, Thirsday,

40、Friday, Saturday, Sunday; char num; for(;) coutnum; if(num 7) coutError!; break; coutpnum - 49endl; 使用new、delete運算符為一任意長度的整型數組分配內存空間,對數組逆序輸出。#includeiostream.h#includestdlib.h void main() int n; int *p; coutn; if(p = new int n) = 0) coutThere is not full memory!n; exit(1); for(int i = 0; i pi; for(i

41、 = n - 1; i = 0; i-) coutpiendl; delete p; 四 問題討論1對多個字符串排序使用何種方法較簡便?2引用本身有無地址?3使用動態內存分配技術時,如果分配不成功,應如何處理?實驗九 函數及其調用 三 實驗內容1. 選擇題(1) B (2) A (3) C (4) D (5) B (6) B (7) D (8) A2. 編程題 編寫一個判斷素數的函數,在主函數中由鍵盤輸入整數的范圍,并給出在該范圍內的所有素數。源程序為:#includeint fun(int n); void main() int m1,m2; coutm1m2; for(int i=m1;i

42、m2;i+) if(fun(i) couti t; int fun(int n) int i; for(i=2;in;i+) if(n%i=0) return 0; return n; 編寫一個函數,根據給定的年、月、日輸出該日是該年的第幾天。在主函數中調用該函數并輸出結果,從鍵盤輸入年、月、日的值。#includeint fun(int,int,int); void main() int year,month,day; coutyearmonthday; while(1) if(year0&month=1&month=1&day=31) coutyear-month-day is the f

43、un(year,month,day)th day of the year!endl; break; else coutyearmonthday; int fun(int year,int month,int day) int ds=day; switch(month-1) case 11:ds+=30; case 10:ds+=31; case 9:ds+=30; case 8:ds+=31; case 7:ds+=31; case 6:ds+=30; case 5:ds+=31; case 4:ds+=30; case 3:ds+=31; case 2: if(year%4=0&year%1

44、00!=0|year%400=0) ds+=29; else ds+=28; case 1:ds+=31; return ds; 編寫兩個函數分別求2n,n!,在主函數中調用這兩個函數計算211!+ 222!+2nn!(n10),并在主函數中輸入n的值,輸出結果。#includedouble fun1(int n);double fun2(int n); void main() int n,i; double s=0; coutn; for(i=1;i=n;i+) s+=fun1(i)*fun2(i); couts=sendl; double fun1(int n) double m=1; f

45、or(int i=1;i=n;i+) m*=2; return m; double fun2(int n) double m=1; for(int i=1;i=n;i+) m*=i; return m; 編寫函數求sin(x),求sin(x)的近似公式為: 在主函數中輸入x的值并調用該函數,輸出結果。#include#includedouble fun(double); void main() double x,sum; coutx; sum=fun(x); coutsum= sumendl; coutsinx=sin(x)1e-6;i+=2) s+=t; t=-t*x*x/(i+1)/(i+

46、2); return s;實驗十 函數與指針 三 實驗內容1. 選擇題 下列程序執行后的輸出結果是_A_。2. 編程題 編寫一個程序,求方程ax2+bx+c=0的根,用三個函數分別求出當b2-4ac大于0,小于0和等于0時的根。要求從主函數輸入a,b,c的值并輸出結果。源程序為:方法1:#include#includevoid root1(double,double,double,double *,double *);double root2(double,double);void root3(double,double,double,double *,double *); void main

47、() double a,b,c,d,x,x1,x2; coutabc; if(a) d=b*b-4*a*c; if(d0) root1(a,b,d,&x1,&x2); coutx1=x1nx2=x2endl; else if(d=0) x=root2(a,b); coutx=xendl; else root3(a,b,d,&x1,&x2); coutx1=x1+x2iendl; coutx2=x1-x2iendl; else if(b) coutx=-c/bn; else if(c) cout方程無根,輸入的a,b,c值有誤!n; else cout方程有無窮多解。n; void root1(

48、double a, double b, double d, double * x1, double * x2) *x1=(-b+sqrt(d)/(2*a); *x2=(-b-sqrt(d)/(2*a); double root2(double a, double b) double x=-b/(2*a); return x; void root3(double a, double b, double d, double * x1, double * x2) *x1=-b/(2*a); *x2=sqrt(-d)/(2*a); 方法2:#include#include void root1(dou

49、ble,double,double,double);void root2(double,double,double);void root3(double,double,double,double);double x1,x2;void main() double a,b,c,t; coutabc; if(a) t=b*b-4*a*c; if (t0) root1(a,b,c,t); coutx1=x1nx2=x2n; else if(t=0) root2(a,b,c); coutx1=x2=x1n; else root3(a,b,c,t); coutx1=x1+x2inx2=x1-x2in; e

50、lse if(b) coutx=-c/bn; else if(c) cout方程無根,輸入的a,b,c值有誤!n; else cout方程有無窮多解。n;void root1(double a,double b,double c,double t) t=sqrt(t); x1=(-b+t)/(2*a); x2=(-b-t)/(2*a); void root2(double a,double b,double c) x1=x2=-b/(2*a);void root3(double a,double b,double c,double t) t=sqrt(-t); x1=-b/(2*a); x2=t/(2*a); 編寫將一個整數n轉換成字符串的函數。在主函數中調用該函數并輸出結果,從鍵盤輸入n的值。例如輸入123,則輸出字符串“123”。n的位數可以任意。#includevoid convert(int n); void main() int number; coutnumber; coutthe output is:endl; if(number0) cout-; number=-number; convert(number); coutendl; void convert(int n) int i; char c; if(i=n/10)!=0)

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論