C++經(jīng)典程序代碼大全_第1頁(yè)
C++經(jīng)典程序代碼大全_第2頁(yè)
C++經(jīng)典程序代碼大全_第3頁(yè)
C++經(jīng)典程序代碼大全_第4頁(yè)
C++經(jīng)典程序代碼大全_第5頁(yè)
已閱讀5頁(yè),還剩130頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、/根據(jù)半徑計(jì)算圓的周長(zhǎng)和面積#include <iostream.h>const float PI=3.1416; /聲明常量(只讀變量)PI為3.1416float fCir_L(float); /聲明自定義函數(shù)fCir_L()的原型 float fCir_S(float); /聲明自定義函數(shù)fCir_S()的原型 /以下是main()函數(shù) main() float r,l,s; /聲明3個(gè)變量 cout<<"r=" /顯示字符串 cin>>r; /鍵盤輸入 l=fCir_L(r); /計(jì)算圓的周長(zhǎng),賦值給變量l s=fCir_S(r)

2、; /計(jì)算圓的面積,賦值給變量s cout<<"l="<<l; /顯示計(jì)算結(jié)果 cout<<"ns="<<s; /定義計(jì)算圓的周長(zhǎng)的函數(shù)fCir_L()float fCir_L(float x) float z=-1.0; /聲明局部變量 if (x>=0.0) /如果參數(shù)大于0,則計(jì)算圓的周長(zhǎng) z=2*PI*x; return(z); /返回函數(shù)值 /定義計(jì)算圓的面積的函數(shù)fCir_S()float fCir_S(float x) float z=-1.0; /聲明局部變量 if (x>=0.

3、0) /如果參數(shù)大于0,則計(jì)算圓的面積 z=PI*x*x; return(z); /返回函數(shù)值 /* Program: P1-2.CPP Written by: Hap Date written: 02:11:10*/#include <iostream.h>void main(void) double s1,s2,s3; s1=1.5; /* 對(duì)變量s1賦值*/ cout<<"s1="<<s1<<endl; /* 對(duì)變量s2賦值*/ s2=2.5; cout<<"s2="<<s2&

4、lt;<endl; s3= /* 對(duì)變量s3賦值*/ 3.5; cout<<"s3="<<s3<<endl; cout<<"s1+s2+s3="<<s1+s2+s3<<endl; /計(jì)算并顯示 /計(jì)算并顯示 cout<<"s1+s2+s3="<<s1+s2+s3<<endl; #include <iostream.h>main() double r=1.0; cout<<"r="

5、<<r<<endl; double l; l=2*3.1416*r; /計(jì)算圓的周長(zhǎng),賦值給變量l cout<<"l="<<l<<endl; /顯示圓的周長(zhǎng) double s=3.1416*r*r; /計(jì)算圓的面積,賦值給變量s cout<<"s="<<s<<endl; /顯示圓的面積 cout<<"r=" /顯示提示輸入的信息 cin>>r; /鍵盤輸入 l=2*3.1416*r; /計(jì)算圓的周長(zhǎng),賦值給變量l c

6、out<<"l="<<l<<endl; /顯示圓的周長(zhǎng) s=3.1416*r*r; cout<<"s="<<s<<endl; /顯示圓的面積#include <iostream.h> /包含iostream.h頭文件void main() /輸出字符常量、變量和字符串 char c1='A' cout<<'W' cout<<c1<<endl; cout<<"This is a tes

7、t."<<endl; cout<<"-"<<endl; /輸出整型常量、變量和表達(dá)式 int n=100; cout<<10; cout<<n; cout<<2*n<<endl; /輸出整型表達(dá)式 cout<<"-"<<endl; /輸出浮點(diǎn)型常量、變量和表達(dá)式 double pi=3.1415926,r=10.0,s=pi*r*r; cout<<pi<<endl; cout<<r; cout<&

8、lt;s; cout<<2*r*pi<<endl; /輸出浮點(diǎn)型表達(dá)式 cout<<"-"<<endl; /一個(gè)cout可以輸出多項(xiàng)數(shù)據(jù) cout<<'W'<<" "<<c1<<endl; cout<<"This is a test."<<endl; cout<<"pi="<<pi<<" r="<<r<<

9、;" s="<<s<<endl;#include <iostream.h> /包含iostream.h頭文件main() /輸入輸出字符 char c; cin>>c; cout<<"c="<<c<<endl; /輸入輸出整型數(shù)據(jù) int n; cin>>n; cout<<"n="<<n<<endl; /輸入輸出浮點(diǎn)型數(shù)據(jù) double x; cin>>x; cout<<"

10、;x="<<x<<endl; /輸入提示 cout<<"n=" cin>>n; cout<<"n="<<n<<endl; /多項(xiàng)輸入 cout<<"c n x"<<endl; cin>>c>>n>>x; cout<<"c="<<c<<" n="<<n<<" x="&

11、lt;<x<<endl;#include <iostream.h> /包含iostream.h頭文件main() /聲明整型變量 int a,b; /從鍵盤上為整型變量賦值 cout<<"a=" cin>>a; cout<<"b=" cin>>b; /整型數(shù)的算術(shù)運(yùn)算 cout<<a<<"+"<<b<<"="<<a+b<<endl; cout<<a<

12、<"-"<<b<<"="<<a-b<<endl; cout<<a<<"*"<<b<<"="<<a*b<<endl; cout<<a<<"/"<<b<<"="<<a/b<<endl; cout<<a<<"%"<<b<<

13、;"="<<a%b<<endl; /測(cè)試溢出 short n=32767,m; /n取short類型的最大值 cout<<"n="<<n<<endl; m=n+1; /引起溢出 cout<<"n+1="<<m<<endl;#include <iostream.h> /包含iostream.h頭文件main() /聲明變量,并初始化 int a=010,b=10,c=0X10; /以十進(jìn)制形式顯示數(shù)據(jù) cout<<&q

14、uot;DEC:" cout<<" a="<<a; cout<<" b="<<b; cout<<" c="<<c<<endl; /以八進(jìn)制形式顯示數(shù)據(jù) cout<<"OCT:" cout<<oct; /指定八進(jìn)制輸出 cout<<" a="<<a; cout<<" b="<<b; cout<<&quo

15、t; c="<<c<<endl; /以十六進(jìn)制形式顯示數(shù)據(jù) cout<<"HEX:" cout<<hex; /指定十六進(jìn)制輸出 cout<<" a="<<a; cout<<" b="<<b; cout<<" c="<<c<<endl; /八、十和十六進(jìn)制數(shù)混合運(yùn)算并輸出 cout<<"a+b+c=" cout<<dec; /恢復(fù)十進(jìn)

16、制輸出 cout<<a+b+c<<endl; /測(cè)試八、十和十六進(jìn)制輸入 cout<<"DEC:a=" cin>>a; cout<<"OCT:b=" cin>>b; cout<<"HEX:a=" cin>>c; cout<<"DEC:"<<dec<<endl; /指定十進(jìn)制輸出 cout<<"a="<<a<<endl; cout&

17、lt;<"b="<<b<<endl; cout<<"c="<<c<<endl;#include <iostream.h> /包含iostream.h頭文件#include<iomanip.h> / iomanip.h頭文件包含setprecision()的定義main() /float型變量的聲明、輸入、計(jì)算和輸出 float fx,fy; cout<<"fx=" cin>>fx; cout<<"fy

18、=" cin>>fy; cout<<fx<<"+"<<fy<<"="<<fx+fy<<endl; cout<<fx<<"-"<<fy<<"="<<fx-fy<<endl; cout<<fx<<"*"<<fy<<"="<<fx*fy<<endl

19、; cout<<fx<<"/"<<fy<<"="<<fx/fy<<endl<<endl; /cout<<fx<<"%"<<fy<<"="<<fx%fy<<endl; Error! /double型變量的聲明、輸入、計(jì)算和輸出 float dx,dy; cout<<"dx=" cin>>dx; cout<<&

20、quot;dy=" cin>>dy; cout<<dx<<"+"<<dy<<"="<<dx+dy<<endl; cout<<dx<<"-"<<dy<<"="<<dx-dy<<endl; cout<<dx<<"*"<<dy<<"="<<dx*dy<&

21、lt;endl; cout<<dx<<"/"<<dy<<"="<<dx/dy<<endl<<endl; /cout<<fx<<"%"<<fy<<"="<<fx%fy<<endl; Error! /測(cè)試float和double類型數(shù)據(jù)的有效位 fx=10.0;fy=6.0; float fz=fx/fy; dx=10.0;dy=6.0; double dz=dx/

22、dy; cout<<"fz=" cout<<setprecision(20)<<fx<<"/"<<fy<<"="<<fz<<endl; cout<<"dz=" cout<<setprecision(20)<<dx<<"/"<<dy<<"="<<dz<<endl<<endl;

23、/float型溢出 float x=3.5e14; cout<<"x="<<x<<endl; cout<<"x*x="<<x*x<<endl; cout<<"x*x*x="<<x*x*x<<endl;#include <iostream.h> /包含iostream.h頭文件main() /字符類型變量的聲明 char c1='A' char c2; /字符數(shù)據(jù)的運(yùn)算及輸出 c2=c1+32; cou

24、t<<"c1="<<c1<<endl; cout<<"c2="<<c2<<endl; /輸出字符及ASCII碼 cout<<c1<<" : "<<int(c1)<<endl; cout<<c2<<" : "<<int(c2)<<endl; cout<<'$'<<" : "<<in

25、t('$')<<endl; /輸入字符 cout<<"c1 c2"<<endl; cin>>c1>>c2; cout<<"c1="<<c1<<" c2="<<c2<<endl;#include <iostream.h> /包含iostream.h頭文件main() char c1='a',TAB='t' /陣鈴一聲 cout<<c1<<

26、;endl; /使用水平制表符 cout<<1<<TAB<<2<<TAB<<3<<TAB<<4<<endl; /使用雙引號(hào) cout<<"He said "Thank you"."<<endl; /使用回車換行 cout<<"abcn"<<"def"<<'n'#include <iostream.h> /包含iostream.h頭文件

27、main() /聲明bool變量,并初始化 bool flag1=false,flag2=true; /輸出布爾常量和變量 cout<<"false:"<<false<<endl; cout<<"true: "<<true<<endl; cout<<"flag1="<<flag1<<endl; cout<<"flag2="<<flag2<<endl; /布爾變量的賦值和輸出

28、 int x=1; flag1=x>0; /存放關(guān)系運(yùn)算結(jié)果 cout<<"flag1="<<flag1<<endl; flag2=flag1; /bool類型變量相互賦值 cout<<"flag2="<<flag2<<endl; /布爾變量超界處理 flag1=100; cout<<"flag1="<<flag1<<endl; flag2=-100; cout<<"flag2="<&

29、lt;flag2<<endl;#include <iostream.h>const double PI=3.1416; /聲明常量(const變量)PI為3.1416main() /聲明3個(gè)變量 double r,l,s; /輸入圓的半徑 cout<<"r=" cin>>r; /計(jì)算圓的周長(zhǎng) l=2*PI*r; cout<<"l="<<l<<endl; /計(jì)算圓的面積 s=PI*r*r; cout<<"s="<<s<<

30、;endl; #include<iostream.h>main() /定義枚舉類型,并指定其枚舉元素的值 enum color RED=3, YELLOW=6, BLUE=9 ; /聲明枚舉變量a和b,并為枚舉變量a賦初值 enum color a=RED; color b; /合法,與C語(yǔ)言不同 / 輸出枚舉常量 cout<<"RED="<<RED<<endl; cout<<"YELLOW="<<YELLOW<<endl; cout<<"BLUE=

31、"<<BLUE<<endl; /枚舉變量的賦值和輸出 b=a; a=BLUE; cout<<"a="<<a<<endl; cout<<"b="<<b<<endl; /a=100; 錯(cuò)誤! /a=6 也錯(cuò)誤! /枚舉變量的關(guān)系運(yùn)算 b=BLUE; / 枚舉變量的賦值運(yùn)算 cout<<"a<b="<<(a<b)<<endl;#include <iostream.h>const

32、 double PI=3.1416; /聲明常量(const變量)PI為3.1416main() /聲明3個(gè)變量 double r=3,l,s; /計(jì)算圓的周長(zhǎng) l=2*PI*r; cout<<"l="<<l<<endl; /計(jì)算圓的面積 s=PI*r*r; cout<<"s="<<s<<endl; /驗(yàn)證賦值誤差 int il,is; il=l; is=s; cout<<"il="<<il<<endl; cout<<

33、;"is="<<is<<endl; #include <iostream.h>main() /變量聲明 char c; double x,y; /測(cè)試自增cout<<"+E and E+ :"<<endl; c='B' cout<<"c="<<+c<<endl; /輸出c=C c='B' cout<<"c="<<c+<<endl; /輸出c=B x=1.

34、5; y=5+ +x; /加號(hào)后的空格不能少 cout<<"y="<<y<<endl; /輸出y=7.5 x=1.5; y=5+x+; cout<<"y="<<y<<endl; /輸出y=6.5 cout<<"-"<<endl;/測(cè)試自減cout<<"-E and E- :"<<endl; c='B' cout<<"c="<<-c<

35、<endl; /輸出c=A c='B' cout<<"c="<<c-<<endl; /輸出c=B x=1.5; y=5+-x; cout<<"y="<<y<<endl; /輸出y=5.5 x=1.5; y=5+x-; cout<<"y="<<y<<endl; /輸出y=6.5#include <iostream.h>main() int a=3, b=2; /輸出關(guān)系表達(dá)式 cout<&l

36、t;a<b<<endl; cout<<(a<b)<<(a>b)<<(a>=b)<<(a=b)<<(a!=b)<<endl; bool flag=2*a<b+10; cout<<"flag="<<flag;#include <iostream.h>main() float a=3.5,b=2.1,c=0; cout<<"a="<<a<<" b="<

37、<b<<" c="<<c<<endl; /與運(yùn)算 cout<<"a&&b="<<(a&&b)<<endl;/輸出1 cout<<"a&&c="<<(a&&c)<<endl;/輸出0 /或運(yùn)算 cout<<"a|b="<<(a|b)<<endl;/輸出1 cout<<"a|c=&quo

38、t;<<(a|c)<<endl;/輸出1 /非運(yùn)算 cout<<"!a="<<!a<<endl<<"!c="<<!c<<endl;/輸出0 1 /關(guān)系運(yùn)算和邏輯運(yùn)算 bool flag=a>=0 && a<=5; /變量a在0,5區(qū)間內(nèi) cout<<"a=>0 && a<=5="<<flag<<endl;/輸出1 /算術(shù)運(yùn)算、關(guān)系運(yùn)算和邏輯運(yùn)算 co

39、ut<<"a+5>2*b+2|a<b+3="<<(a+5>2*b+2|a<b+3)<<endl;/輸出1#include <iostream.h>main() /按位與運(yùn)算 cout<<"24&12="<<(24&12)<<endl; /按位異或運(yùn)算 cout<<"2412="<<(2412)<<endl; /按位或運(yùn)算 cout<<"24|12=&quo

40、t;<<(24|12)<<endl; /按位取反運(yùn)算 cout<<"24="<<(24)<<endl; /左移位運(yùn)算 cout<<"5<<3="<<(5<<3)<<endl; cout<<"-5<<3="<<(-5<<3)<<endl; /右移位運(yùn)算 cout<<"5>>3="<<(5>>3

41、)<<endl; cout<<"-5>>3="<<(-5>>3)<<endl;#include <iostream.h>main() int a=1,b=1,c=3; /顯示a,b,c的值 cout<<"a="<<a<<" b="<<b<<" c="<<c<<endl; /計(jì)算顯示(1) b+=a+2*c%5; 的結(jié)果 b+=a+2*c%5; /相當(dāng)

42、于表達(dá)式語(yǔ)句 b=b+(a+2*c%5); cout<<"(1) b="<<b<<endl; /計(jì)算顯示(2) a<<=c-2*b; 的結(jié)果 a=1,b=1,c=3; a<<=c-2*b; / 相當(dāng)于表達(dá)式語(yǔ)句 a=a<<(c-2*b); cout<<"(2) a="<<a<<endl; /計(jì)算顯示(3) a*=b=c=3;的結(jié)果 a=1,b=1,c=3; a*=b=c=3; /相當(dāng)于語(yǔ)句組 c=3;b=c;a=a*b; cout<<&

43、quot;(3) a="<<a<<" b="<<b<<" c="<<c<<endl; /計(jì)算顯示(4) a+=b+=c;的結(jié)果 a=1,b=1,c=3; a+=b+=c; /相當(dāng)于語(yǔ)句組 b=b+c; a=a+b; cout<<"(4) a="<<a<<" b="<<b<<" c="<<c<<endl; /計(jì)算顯示(5) a-=b=

44、+c+2;的結(jié)果 a=1,b=1,c=3; a-=b=+c+2; /相當(dāng)于語(yǔ)句組 +c;b=b+c+2;a=a-b; cout<<"(5) a="<<a<<" b="<<b<<" c="<<c<<endl;#include <iostream.h>main() /用 sizeof 計(jì)算各類種常量的字節(jié)長(zhǎng)度 cout<<"sizeof('$')="<<sizeof('$

45、9;)<<endl; cout<<"sizeof(1)="<<sizeof(1)<<endl; cout<<"sizeof(1.5)="<<sizeof(1.5)<<endl; cout<<"sizeof("Good!")="<<sizeof("Good!")<<endl; /用sizeof 計(jì)算各類型變量的字節(jié)長(zhǎng)度 int i=100; char c='A'

46、float x=3.1416; double p=0.1; cout<<"sizeof(i)="<<sizeof(i)<<endl; cout<<"sizeof(c)="<<sizeof(c)<<endl; cout<<"sizeof(x)="<<sizeof(x)<<endl; cout<<"sizeof(p)="<<sizeof(p)<<endl; /用sizeof 計(jì)

47、算表達(dá)式的字節(jié)長(zhǎng)度 cout<<"sizeof(x+1.732)="<<sizeof(x+1.732)<<endl; /用 sizeof 計(jì)算各類型的字節(jié)長(zhǎng)度 cout<<"sizeof(char)="<<sizeof(char)<<endl; cout<<"sizeof(int)="<<sizeof(int)<<endl; cout<<"sizeof(float)="<<sizeof

48、(float)<<endl; cout<<"sizeof(double)="<<sizeof(double)<<endl; /用sizeof 計(jì)算數(shù)組的字節(jié)長(zhǎng)度 char str="This is a test." int a10; double xy10; cout<<"sizeof(str)="<<sizeof(str)<<endl; cout<<"sizeof(a)="<<sizeof(a)<&l

49、t;endl; cout<<"sizeof(xy)="<<sizeof(xy)<<endl; /用sizeof 計(jì)算自定義類型的長(zhǎng)度 struct st short num; float math_grade; float Chinese_grade; float sum_grade; ; st student1; cout<<"sizeof(st)="<<sizeof(st)<<endl; cout<<"sizeof(student1)="<&

50、lt;sizeof(student1)<<endl;#include <iostream.h>main() /聲明變量語(yǔ)句中使用順序運(yùn)算 int x, y; /計(jì)算中使用順序運(yùn)算 x=50; y=(x=x-5, x/5); cout<<"x="<<x<<endl; cout<<"y="<<y<<endl;#include <iostream.h>main() /測(cè)試表達(dá)式類型的轉(zhuǎn)換 int n=100,m; double x=3.791,y; co

51、ut<<"n*x="<<n*x<<endl; /賦值類型轉(zhuǎn)換 m=x; y=n; cout<<"m="<<m<<endl; cout<<"y="<<y<<endl; /強(qiáng)制類型轉(zhuǎn)換 cout<<"int(x)="<<int(x)<<endl; cout<<"(int)x="<<(int)x<<endl; cout<

52、;<"int(1.732+x)="<<int(1.732+x)<<endl; cout<<"(int)1.732+x="<<(int)1.723+x<<endl; cout<<"double(100)="<<double(100)<<endl;#include <iostream.h>main() float a,b,s; cout<<"a b"<<endl; cin>&g

53、t;a>>b; /利用cin從鍵盤上為變量 a,b 賦值 s=a; if (a<b) s=b; /if語(yǔ)句中只有這一個(gè)語(yǔ)句,可省略花括號(hào) s=s*s; /變量s中保存a,b中較大的一個(gè)數(shù)的平方 cout<<"s="<<s;#include <iostream.h>main() int x,y; cout<<"x=" cin>>x; if (x<=0) /滿足條件執(zhí)行 y=2*x; cout<<"y="<<y; /輸出結(jié)果 els

54、e /不滿足條件執(zhí)行 y=x*x; cout<<"y="<<y; /輸出結(jié)果 #include <iostream.h>main() int a,b,c; int smallest; cout<<"a b c"<<endl; cin>>a>>b>>c; if (a<=b) /外層條件語(yǔ)句 if (a<=c) /內(nèi)層條件語(yǔ)句 smallest=a; else smallest=c; else if (b<=c) /內(nèi)層條件語(yǔ)句 smallest

55、=b; else smallest=c; cout<<"Smallest="<<smallest<<endl;#include <iostream.h>main() int score; /從鍵盤上輸入分?jǐn)?shù) cout<<"score=" cin>>score; /用帶else if的條件語(yǔ)句判斷處理 if (score<0 | score>100) cout<<"The score is out of range!"<<endl

56、; else if (score>=90) cout<<"Your grade is a A."<<endl; else if (score>=80) cout<<"Your grade is a B."<<endl; else if (score>=70) cout<<"Your grade is a C."<<endl; else if (score>=60) cout<<"Your grade is a D.&q

57、uot;<<endl; else cout<<"Your grade is a E."<<endl;#include <iostream.h>main() int n; cout<<"n=" cin>>n; if (n>=0 && n<=100 &&n%2=0) cout<<"n="<<n<<endl; else cout<<"The "<<

58、n<<" is out of range!"<<endl;#include <iostream.h>main() int a,b,Max; /輸入數(shù)據(jù) cout<<"a=" cin>>a; cout<<"b=" cin>>b; /找出較大值 Max=a>b?a:b; cout<<"Max="<<Max<<endl;#include <iostream.h>main() int a

59、,b; /輸入數(shù)據(jù) cout<<"a=" cin>>a; cout<<"b=" cin>>b; /除法判斷 if (b!=0 && a%b=0) cout<<b<<" divides "<<a<<endl; cout<<"a/b="<<a/b<<endl; else cout<<b<<" does not divide "&l

60、t;<a<<endl;#include <iostream.h>main() /x,y 為操作數(shù),c為運(yùn)算符 int x,y,z; char c1; cin>>x>>c1>>y; /c1 /多路選擇語(yǔ)句選擇不同表達(dá)式計(jì)算語(yǔ)句 switch(c1) case '+':cout<<x<<"+"<<y<<"="<<x+y<<endl; break; case '-':cout<<x

61、<<"-"<<y<<"="<<x-y<<endl; break; case '*':cout<<x<<"*"<<y<<"="<<x*y<<endl; break; case '/':cout<<x<<"/"<<y<<"="<<x/y<<endl

62、; break; case '%':cout<<x<<"%"<<y<<"="<<x%y<<endl; break; default :cout<<"Wrong !"<<endl; /當(dāng)不符合上述情況時(shí)執(zhí)行本子句 #include<iostream.h>float x=365.5; /聲明全局變量main() int x=1,y=2; double w=x+y; double x=1.414,y=1.732,z=3

63、.14; cout<<"inner:x="<<x<<endl; cout<<"inner:y="<<y<<endl; cout<<"inner:z="<<z<<endl; cout<<"outer:w="<<w<<endl; cout<<":x="<<:x<<endl; /訪問重名的全局變量 cout<<&

64、quot;outer:x="<<x<<endl; cout<<"outer:y="<<y<<endl; cout<<"outer:w="<<w<<endl; /cout<<"inner:z="<<z<<endl;無(wú)效 cout<<":x="<<:x<<endl; /訪問重名的全局變量#include<iostream.h>mai

65、n() /顯示1,2,3.10 for(int i=1;i<=10;i+) cout<<i<<" " cout<<endl; /顯示10,9,8.1 for(int j=10;j>=1;j-) cout<<j<<" " cout<<endl; /顯示1,3,5.9 for(int k=1;k<=10;k=k+2) cout<<k<<" " cout<<endl; /顯示ABC.Z for(char c='

66、;A'c<='Z'c+) cout<<c; cout<<endl; /顯示0,0.1,0.2.1.0 for(float x=0;x<=1.0;x=x+0.1) cout<<x<<" " cout<<endl; /顯示0,0.1,0.2.1.0 for(float x1=0;x1<=1.0+0.1/2;x1=x1+0.1) cout<<x1<<" " cout<<endl; /計(jì)算s=1+2+3.+100 int s=

67、0; for(int n=1;n<=100;n+) s=s+n; cout<<"s="<<s<<endl;#include<iostream.h>main() /計(jì)算s=1+2+3.+100 int s=0,n=1; while(n<=100) s=s+n; n+; cout<<"s="<<s<<endl; /累加鍵盤輸入的數(shù)據(jù) double x,sum=0.0; cout<<"x=" cin>>x; while(x

68、!=0) sum+=x; cout<<"x=" cin>>x; cout<<"sum="<<sum<<endl;#include<iostream.h> main() /計(jì)算s=1+2+3.+100 int s=0,n=0; do n+; s+=n; while(n<100); cout<<"s="<<s<<endl; /累加鍵盤輸入的數(shù)據(jù) double x,sum=0.0; do cout<<"x=" cin>>x; sum+=x; while(x!=0);

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論