欧美色欧美亚洲高清在线观看,国产特黄特色a级在线视频,国产一区视频一区欧美,亚洲成a 人在线观看中文

  1. <ul id="fwlom"></ul>

    <object id="fwlom"></object>

    <span id="fwlom"></span><dfn id="fwlom"></dfn>

      <object id="fwlom"></object>

      C語言實(shí)驗(yàn)報(bào)告

      時間:2019-05-12 08:38:02下載本文作者:會員上傳
      簡介:寫寫幫文庫小編為你整理了多篇相關(guān)的《C語言實(shí)驗(yàn)報(bào)告》,但愿對你工作學(xué)習(xí)有幫助,當(dāng)然你在寫寫幫文庫還可以找到更多《C語言實(shí)驗(yàn)報(bào)告》。

      第一篇:C語言實(shí)驗(yàn)報(bào)告

      實(shí)驗(yàn)一 C程序的運(yùn)行環(huán)境和方法

      一、實(shí)驗(yàn)?zāi)康?/p>

      1.了解所用的計(jì)算機(jī)系統(tǒng)。

      2.了解在該系統(tǒng)上如何進(jìn)行編輯、編譯、連接和運(yùn)行一個C程序。3.通過運(yùn)行簡單的C程序了解C程序的特點(diǎn)。

      二、實(shí)驗(yàn)內(nèi)容和步驟

      1.熟悉所用的系統(tǒng)。了解Windows資源管理器的使用方法:文件的查看、復(fù)制、運(yùn)行等方法,Visual C++所在目錄,文本文件的建立方法。2.進(jìn)入Visual C++,并新建一個C++源程序文件。

      3.熟悉Visual C++的集成環(huán)境,了解各菜單項(xiàng)有哪些子菜單。4.輸入下面的程序(教材中的例1.1),注意區(qū)分大小寫。

      #include void main(){ printf(“This is a C program.n”);} 編譯并運(yùn)行程序。結(jié)果為:

      5.關(guān)閉工作區(qū),新建一個程序,然后對教材中的例1.2重復(fù)4中的操作(即只將程序改為例1.2中的程序,其它操作步驟相同)。其程序?yàn)椋?/p>

      #include int main(){ int a,b,sum;a=123;b=456;sum=a+b;printf(“sum is %dn”,sum);return 0;} 運(yùn)行結(jié)果為:

      6.關(guān)閉工作區(qū),新建一個程序,然后輸入并運(yùn)行一個需要在運(yùn)行時輸入數(shù)據(jù)的程序

      #include void main(){int a,b,c;int max(int x,int y);

      printf(“input a and b:n”);scanf(“%d,%d”,&a,&b);c=max(a,b);printf(“nmax=%dn”,c);} int max(int x,int y){int z;if(x>y)z=x;else z=y;return(z);}(1)運(yùn)行程序,若程序有錯,則修改錯誤后繼續(xù)運(yùn)行程序,當(dāng)沒有錯誤信息時輸入:2,5并按Enter鍵,查看運(yùn)行結(jié)果。

      其運(yùn)行結(jié)果為:

      (2)將程序的第三行改為:int a;b;c;然后按F9看結(jié)果如何,將其修改為int a,b,c;將子程序max的第3,4行合并為一行,運(yùn)行程序,看結(jié)果是否相同。將程序的第三行改為:int a;b;c;運(yùn)行結(jié)果為:

      將子程序max的第3,4行合并為一行,運(yùn)行程序,其結(jié)果相同,結(jié)果為:

      7.運(yùn)行一個自己編寫的程序,程序的功能是輸出兩行文字。其程序?yàn)椋?/p>

      #include void main(){ printf(“我是中國人!n”);printf(“我深深的愛著我的祖國!n”);} 運(yùn)行結(jié)果為:

      實(shí)驗(yàn)二 數(shù)據(jù)類型、運(yùn)算符和表達(dá)式

      一、實(shí)驗(yàn)?zāi)康?/p>

      1.掌握C語言數(shù)據(jù)類型,熟悉如何定義一個整型、字符型和實(shí)型的變量,以及對它們賦值的方法。

      2.掌握不同數(shù)據(jù)類型之間賦值的規(guī)律。

      3.學(xué)會使用C的有關(guān)算術(shù)運(yùn)算符,以及包含這些運(yùn)算符的表達(dá)式,特別是自加(++)和自減(――)運(yùn)算符的使用。

      4.進(jìn)一步熟悉C程序的編輯、編譯、連接和運(yùn)行的過程。

      二、實(shí)驗(yàn)內(nèi)容和步驟

      1.輸入并運(yùn)行下面的程序 #include void main(){char c1,c2;c1='a';c2='b';printf(“%c %c”,c1,c2);}(1)運(yùn)行此程序 其結(jié)果為:

      (2)加入下面的一個語句作為“}”前的最后一個語句:

      printf(“%d,%dn”,c1,c2);其結(jié)果為:

      (3)將第3行改為:

      int c1,c2;然后再運(yùn)行程序,并觀察結(jié)果是否相同。相同,其結(jié)果為:

      (4)將第3行改為int c1,c2;將第4,5行依次改為:

      c1=a;c2=b;c1=“a”;c2=“b” c1=300;c2=400;每改為一次后運(yùn)行程序,觀察結(jié)果。其程序?yàn)椋?/p>

      #include void main(){int c1,c2;c1='a',c2='b';c1=300;c2=400;printf(“%c %cn”,c1,c2);printf(“%d %dn”,c1,c2);} 其結(jié)果為:

      2.分析教材第3章習(xí)題3.5中的程序的運(yùn)行結(jié)果,然后輸入該程序并運(yùn)行,將運(yùn)行結(jié)果與前面分析的結(jié)果對比。其程序?yàn)椋?/p>

      #include int main(){int a,b;float x,y;char c1,c2;scanf(“a=%d b=%d”,&a,&b);scanf(“%f %e”,&x,&y);scanf(“%c %c”,&c1,&c2);printf(“a=%d,b=%d,x=%f,y=%f,c1=%c,c2=%cn”,a,b,x,y,c1,c2);return 0;} 其運(yùn)行結(jié)果為:

      3.輸入并運(yùn)行下面的程序

      #include void main(){int a,b;unsigned c,d;long e,f;a=100;b=-100;e=50000;f=32767;c=a;d=b;printf(“%d,%dn”,a,b);3

      printf(“%u,%un”,a,b);printf(“%u,%un”,c,d);c=a=e;d=b=f;printf(“%d,%dn”,a,b);printf(“%u,%un”,c,d);} 請對照程序和運(yùn)行結(jié)果分析: 運(yùn)行結(jié)果為:

      (1)將一個負(fù)整數(shù)賦給一個無符號的變量,會得到什么結(jié)果。畫出它們在內(nèi)存中的表示形式。

      (2)將一個大于32767的長整數(shù)賦給一個整型變量,會得到什么結(jié)果。畫出它們在內(nèi)存中的表示形式。

      (3)將一個長整數(shù)賦給無符號的變量,會得到什么結(jié)果。畫出它們在內(nèi)存中的表示形式。4.輸入習(xí)題3.10(1)運(yùn)行程序,注意i,j,m,n的值。(2)將第4,5行改為:

      m=i++;n=++j;再運(yùn)行。(3)將程序改為:

      #include void main(){int i,j;i=8;j=10;printf(“%d,%dn”,++i,++j);i=8;j=10;printf(“%d,%dn”,i++,j++);i=8;j=10;printf(“%d,%dn”,++i,i);i=8;j=10;printf(“%d,%dn”,i++,i);} 運(yùn)行程序并分析運(yùn)行結(jié)果。其結(jié)果為:

      5.按習(xí)題3.6的要求編程并上機(jī)運(yùn)行:

      要將“China”譯成密碼,密碼規(guī)律是:用原來的字母后面第4個字母代替原來的字母。例如,字母“A”后面第4個字母是“E”,用“E”代替“A”,因此,“China”應(yīng)譯為“Glmre”。請編一程序,用賦初值的方法使c1、c2、c3、c4、c5這5個變量的值分別為’C’,'h', 'i','n', 'a',經(jīng)過計(jì)算,使c1、c2、c3、c4、c5分別變?yōu)椋?G','l','m',r','e',并輸出.程序提示:

      main函數(shù)算法如下:

      定義char型變量 c1,c2,c3,c4,c5;給字符型變量賦值 c1=c1+4;c2=c2+4;c3=c3+4;c4=c4+4;c5=c5+4;輸出c1,c2,c3,c4,c5 其程序?yàn)椋?#include int main(){char c1='C',c2='h',c3='i',c4='n',c5='a';c1=c1+4;c2=c2+4;c3=c3+4;c4=c4+4;c5=c5+4;printf(“password is %c%c%c%c%cn”,c1,c2,c3,c4,c5);return 0;} 其運(yùn)行結(jié)果為:

      實(shí)驗(yàn)三 最簡單的C程序設(shè)計(jì)

      一、實(shí)驗(yàn)?zāi)康?/p>

      1.掌握C語言中使用最多的一種語句――賦值語句的使用方法。2.掌握各種類型數(shù)據(jù)的輸入輸出方法,能正確使用各種格式輸出符。

      二、實(shí)驗(yàn)內(nèi)容和步驟

      1.掌握各種格式輸出符的使用方法。#include void main(){int a,b;float d,e;char c1,c2;5

      double f,g;long n,m;unsigned p,q;a=61;b=62;c1='a';c2='b';d=3.56;e=-6.87;f=3156.890121;g=0.123456789;m=50000;n=-60000;p=32768;q=40000;printf(“a=%d,b=%dnc1=%c,c2=%cnd=%6.2f,e=%6.2fn”,a,b,c1,c2,d,e);printf(“f=%15.6f,g=%15.12fnm=%ld,n=%ldnp=%u,q=%un”,f,g,m,n,p,q);}(1)運(yùn)行此程序并分析運(yùn)行結(jié)果。其結(jié)果為:

      (2)在此基礎(chǔ)上,修改程序的第9-14行:

      a=61;b=62;c1=a;c2=b;f=3156.890121;g=0.123456789;d=f;e=g;p=a=m=50000;q=b=n=-60000;運(yùn)行程序,分析運(yùn)行結(jié)果。其結(jié)果為:

      (3)將9-14行改為以下的scanf語句,即用scanf函數(shù)接收從鍵盤輸入的數(shù)據(jù):

      scanf(“%d,%d,%c,%c,%f,%f,%lf,%lf,%ld,%ld,%u,%u”,&a,&b,&c1,&c2,&d,&e,&f,&g,&m,&n,&p,&q);運(yùn)行程序(無錯誤的情況下)輸入數(shù)據(jù)如下:

      61,62,a,b,3.56,-6.87,3156,890121,0.123456789,50000,-60000,32768,40000 其結(jié)果為:

      2.按習(xí)題3.8的要求編寫程序并運(yùn)行:

      設(shè)圓半徑r=1.5,圓柱高h(yuǎn)=3,求圓周長、圓面積,圓球表面積、圓球體積、圓柱體體積。用scanf輸入數(shù)據(jù),輸出計(jì)算結(jié)果,輸出時要有文字說明,取小數(shù)后2位數(shù)字。其程序?yàn)椋?/p>

      #include int main(){float h,r,l,s,sq,vq,vz;float pi=3.141526;printf(“請輸入圓半徑r,圓柱高h(yuǎn):”);scanf(“%f,%f”,&r,&h);l=2*pi*r;s=r*r*pi;sq=4*pi*r*r;vq=3.0/4.0*pi*r*r*r;vz=pi*r*r*h;printf(“圓周長為:l=%6.2fn”,l);printf(“圓面積為:s=%6.2fn”,s);printf(“圓球面積為:sq=%6.2fn”,sq);printf(“圓球體積為:vq=%6.2fn”,vq);printf(“圓柱體積為:%6.2fn”,vz);return 0;} 其運(yùn)行結(jié)果為:

      3.編寫程序,用getchar函數(shù)輸入兩個字符給c1,c2,然后分別用putchar函數(shù)和printf函數(shù)輸出這兩個字符。其程序?yàn)椋?/p>

      #include void main(){ char c1,c2;printf(“請輸入兩個字符: c1,c2 :”);

      c1=getchar();c2=getchar();printf(“用putchar語句輸出結(jié)果為:”);putchar(c1);putchar(c2);printf(“n”);printf(“用printf語句輸出結(jié)果為:”);printf(“%c%cn”,c1,c2);} 其運(yùn)行結(jié)果為:

      實(shí)驗(yàn)四 選擇結(jié)構(gòu)程序設(shè)計(jì)

      一、實(shí)驗(yàn)?zāi)康?/p>

      1.了解C語言表示邏輯值的方法。

      2.學(xué)會正確使用邏輯運(yùn)算符和邏輯表達(dá)式的方法。3.熟悉if語句和switch語句。4.結(jié)合程序掌握一些簡單的算法。5.學(xué)習(xí)調(diào)試程序的方法。

      二、實(shí)驗(yàn)內(nèi)容

      本實(shí)驗(yàn)要求編程解決以下問題,然后上機(jī)調(diào)試運(yùn)行程序。

      x?1?x?1?x?101.y??2x?1?3x?11x?10?

      用scanf函數(shù)輸入x的值,求y的值。

      其程序?yàn)椋?/p>

      #include void main(){ int x,y;printf(“請輸入x:n”);scanf(“%d”,&x);if(x<1)y=x;else if(x<10)y=2*x-1;

      else y=3*x-11;printf(“x=%d,y=%dn”,x,y);} 運(yùn)行結(jié)果為:

      2.給出一個百分制的成績,要求輸出成績等級A,B,C,D,E,90分及以上為A,80-89為B,70-79為C,60-69為D,60分以下為E。要求從鍵盤輸入成績,然后輸出相應(yīng)等級,分別用if語句和switch語句實(shí)現(xiàn)。(1)使用if語句的程序如下: #include void main(){ float score;char grade;printf(“請輸入學(xué)生成績:n”);scanf(“%f”,&score);if(score>=90)grade='A';else if(score>=80)grade='B';else if(score>=70)grade='C';else if(score>=60)grade='D';else grade='E';printf(“成績是%-5.1f,相應(yīng)的等級是%cn”,score,grade);} 運(yùn)行結(jié)果為:

      (2)使用switch語句程序如下: #include void main(){ float score;char grade;printf(“請輸入學(xué)生成績:n”);scanf(“%f”,&score);switch(int(score/10)){ case 10: case 9: grade='A';break;case 8: grade='B';break;case 7: grade='C';break;case 6: grade='D';break;default: grade='E';break;}

      printf(“成績是%-5.1f,相應(yīng)的等級是%cn”,score,grade);} 其運(yùn)行結(jié)果與使用if語句運(yùn)行結(jié)果一樣。

      3.編程實(shí)現(xiàn):輸入一個不多于5位的正整數(shù),要求:(1)輸出它是幾位數(shù),(2)分別輸出每一位數(shù)字,(3)按逆序輸出各位數(shù)字,如原數(shù)為321,則應(yīng)輸出123。應(yīng)準(zhǔn)備以下測試數(shù)據(jù)

      要處理的數(shù)為1位正整數(shù); 要處理的數(shù)為2位正整數(shù); 要處理的數(shù)為3位正整數(shù); 要處理的數(shù)為4位正整數(shù); 要處理的數(shù)為5位正整數(shù);

      除此之外,程序還應(yīng)當(dāng)對不合法的輸出作必要的處理。例如: 輸入負(fù)數(shù);

      輸入的數(shù)超過5位; 其程序?yàn)椋?/p>

      #include #include int main()10

      { int num,indiv,ten,hundred,thousand,ten_thousand,place;printf(“請輸入一個整數(shù)(0-99999):n”);scanf(“%d”,&num);if(num>99999)printf(“輸入的數(shù)超過5位!n”);else if(num<0)printf(“輸入的數(shù)是一個負(fù)數(shù)!n”);else { if(num>9999)place=5;else if(num>999)place=4;else if(num>99)place=3;else if(num>9)place=2;else place=1;if(num>99999||num<0)printf(“enter num is error!n”);printf(“位數(shù):%dn”,place);printf(“每位數(shù)字為:”);ten_thousand=num/10000;thousand=(int)(num-ten_thousand*10000)/1000;hundred=(int)(num-ten_thousand*10000-thousand*1000)/100;ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;indiv=(int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);switch(place){case 5:printf(“%d,%d,%d,%d,%d”,ten_thousand,thousand,hundred,ten,indiv);printf(“n反序數(shù)字為:”);printf(“%d%d%d%d%d”,indiv,ten,hundred,thousand,ten_thousand);break;case 4:printf(“%d,%d,%d,%d”,thousand,hundred,ten,indiv);printf(“n反序數(shù)字為:”);printf(“%d%d%d%d”,indiv,ten,hundred,thousand);break;case 3:printf(“%d,%d,%d”,hundred,ten,indiv);printf(“n反序數(shù)字為:”);printf(“%d%d%d”,indiv,ten,hundred);break;case 2:printf(“%d,%d”,ten,indiv);printf(“n反序數(shù)字為:”);11

      printf(“%d%d”,indiv,ten);break;case 1:printf(“%d”,indiv);printf(“n反序數(shù)字為:”);printf(“%d”,indiv);break;} printf(“n”);return 0;} }

      4.編程實(shí)現(xiàn):輸入4個整數(shù),要求按由小到大的順序輸出。得到正確結(jié)果后,修改程序使之按由大到小的順序輸出。由小到大順序輸出其程序?yàn)椋?#include void main(){int t,a,b,c,d;printf(“請輸入四個數(shù):”);scanf(“%d,%d,%d,%d,%d”,&a,&b,&c,&d);if(a>b){t=a;a=b;b=t;} if(a>c){t=a;a=c;c=t;} 12

      if(a>d){t=a;a=d;d=t;} if(b>c){t=b;b=c;c=t;} if(b>d){t=b;b=d;d=t;} if(c>d){t=c;c=d;d=t;} printf(“排序結(jié)果為:n”);printf(“%d %d %d %dn”,a,b,c,d);} 其運(yùn)行結(jié)果為:

      由大到小順序輸出其程序?yàn)椋?將上面程序第十九行改為:

      printf(“%d %d %d %dn”,d,c,b,a);其運(yùn)行結(jié)果為:

      5.已知a=12,b=6,要求輸入一個算術(shù)運(yùn)算符(+、-、*、/),對a,b進(jìn)行算術(shù)運(yùn)算,并輸出結(jié)果。其程序?yàn)椋?/p>

      #include int main(){int a=12,b=6,c;char ch;printf(“請輸入一個四則運(yùn)算的符號:n”);scanf(“%c”,&ch);printf(“The result is:”);switch(ch){ case'+':printf(“a+b=%dn”,a+b);break;case'-':printf(“a-b=%dn”,a-b);break;case'*':printf(“a*b=%dn”,a*b);break;case'/':printf(“a/b=%dn”,a/b);break;} return 0;} 其運(yùn)行結(jié)果為:

      實(shí)驗(yàn)五 循環(huán)控制

      一、實(shí)驗(yàn)?zāi)康?/p>

      熟悉使用while語句,do-while語句和for語句實(shí)現(xiàn)循環(huán)的方法。掌握在程序設(shè)計(jì)中用循環(huán)的方法實(shí)現(xiàn)一些常用算法(如窮舉、迭代、遞推等)。

      二、實(shí)驗(yàn)內(nèi)容

      1.上機(jī)完成習(xí)題6.1:輸入兩個正整數(shù)m和n,求出它們的最大公約數(shù)和最小公倍數(shù)。

      輸入時,使m

      修改程序使對任何的整數(shù)都能得到正確的結(jié)果。其程序?yàn)椋?/p>

      #include void main(){ int p,r,n,m,temp;printf(“請輸入兩個正整數(shù) n,m:n”);scanf(“%d,%d”,&n,&m);if(n

      2.編寫程序利用公式:e?1?其程序?yàn)椋?/p>

      #include

      111????求e的近似值,精確到小數(shù)后6位 1!2!n!

      void main(){ int n,i;double e,p,t;printf(“輸入n的值:n”);scanf(“&d”,&n);e=1;t=1;p=1;i=1;while(t>=1e-7){e=e+t;i++;p=p*i;t=1.0/p;} printf(“The e is %fn”,e);} 其運(yùn)行結(jié)果為:

      3.編程求1到n中能被3或7整除的數(shù)之和。分別用for循環(huán)語句和while循環(huán)語句完成本題。

      用for循環(huán),其程序?yàn)椋?#include void main(){ int i,n,sum=0;printf(“請輸入一個整數(shù):n”);scanf(“%d”,&n);for(i=1;i<=n;i++)if(i%3==0||i%7==0)sum=sum+i;printf(“The sum is %dn”,sum);} 其運(yùn)行結(jié)果為:

      用while循環(huán)語句,其程序?yàn)椋?/p>

      #include void main(){ 15

      int i=1,n,sum=0;printf(“請輸入一個整數(shù):n”);scanf(“%d”,&n);while(i<=n){ if(i%3==0||i%7==0)sum=sum+i;i++;} printf(“The sum is %dn”,sum);}

      4.上機(jī)完成習(xí)題6.10:猴子吃桃問題。猴子第一天摘下若干個桃子,當(dāng)即吃了一半,還不過癮,又多吃了一個。第二天早上又將剩下的桃子吃掉了一半,又多吃了一個。以后每天早上都吃了前一天剩下的一半零一個。到第10天早上想再吃時,見只剩下一個桃子了。求第一天共摘了多少桃子。

      在得到正確結(jié)果后,修改題目,改為每天早上都吃了前一天剩下的一半加二個,請修改程序,并運(yùn)行,檢查運(yùn)行結(jié)果是否正確。其程序?yàn)椋?/p>

      #include void main(){ int day,x=1,x1;for(day=9;day>=1;day--){ x=2*(x+1);x1=x;} printf(“total=%dn”,x1);} 其運(yùn)行結(jié)果為:

      實(shí)驗(yàn)六 數(shù)組

      一、實(shí)驗(yàn)?zāi)康?/p>

      1.掌握一維數(shù)組與二維數(shù)組的定義、賦值及輸入輸出方法。2.掌握字符數(shù)組和字符串函數(shù)的使用。

      3.掌握與數(shù)組有關(guān)的算法(特別是排序算法)

      二、實(shí)驗(yàn)內(nèi)容

      1.用選擇法對10個整數(shù)排序。10個整數(shù)用scanf函數(shù)輸入。其程序?yàn)椋?/p>

      #include void main(){int i,j,min,temp,a[11];printf(“enter data:n”);for(i=1;i<=10;i++){printf(“a[%d]=”,i);scanf(“%d”,&a[i]);} printf(“n”);printf(“The orginal numbers:n”);for(i=1;i<=10;i++)printf(“%5d”,a[i]);printf(“n”);for(i=1;i<=9;i++){min=i;for(j=i+1;j<=10;j++)if(a[min]>a[j])min=j;temp=a[i];a[i]=a[min];a[min]=temp;} printf(“nThe sorted numbers:n”);for(i=1;i<=10;i++)printf(“%5d”,a[i]);printf(“n”);} 其運(yùn)行結(jié)果為:

      2.有15個數(shù)存放在一個數(shù)組中,輸入一個數(shù)要求用折半查找法找出該數(shù)是數(shù)組中的第幾個元素的值,如果該數(shù)不在數(shù)組中,則輸出無此數(shù),要找的數(shù)用scanf函數(shù)輸入。其程序?yàn)椋?/p>

      #include # define N 15 int main(){int i,number,top,bott,mid,loca,a[N],flag=1,sign;char c;printf(“enter data:n”);scanf(“%d”,&a[0]);i=1;while(ia[i-1])i++;else printf(“enter this data again;n”);} printf(“n”);while(flag){ printf(“input number to look for:”);scanf(“%d”,&number);

      sign=0;

      top=0;

      bott=N-1;

      if(numbera[N-1])

      loca=-1;

      while((!sign)&&(top<=bott))

      {

      mid=(bott+top)/2;

      if(number==a[mid])

      {loca=mid;

      printf(“Has found %d,its position is %dn”,number,loca+1);

      sign=1;

      }

      else if(number

      bott=mid-1;

      else

      top=mid+1;

      }

      if(!sign||loca==-1)

      printf(“cannot find %d.n”,number);

      printf(“continue or not(Y/N)?”);

      scanf(“%c”,&c);

      if(c=='N'||c=='n')

      flag=0;} return 0;} 其運(yùn)行結(jié)果為:

      3.將兩個串連接起來,不要用strcat函數(shù)。其程序?yàn)椋?/p>

      #include int main(){ char s1[80],s2[40];int i=0,j=0;printf(“input string1:”);scanf(“%s”,s1);printf(“input string2:”);scanf(“%s”,s2);while(s1[i]!='