欧美色欧美亚洲高清在线观看,国产特黄特色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í)間:2019-05-15 01:00:11下載本文作者:會(huì)員上傳
      簡(jiǎn)介:寫寫幫文庫(kù)小編為你整理了多篇相關(guān)的《c語言課后答案》,但愿對(duì)你工作學(xué)習(xí)有幫助,當(dāng)然你在寫寫幫文庫(kù)還可以找到更多《c語言課后答案》。

      第一篇:c語言課后答案

      c語言課后答案

      第一章習(xí)題答案

      一、選擇題

      1~5:BDCDA 6~10:DABBB 11~12:CC

      二、填空題

      1、main()

      2、函數(shù)首部,函數(shù)體

      3、函數(shù)

      4、編輯、編譯、連接、運(yùn)行

      5、.cpp、.obj、.exe

      6、;或 分號(hào)

      三、編程題

      #include

      /* 包含標(biāo)準(zhǔn)庫(kù)的信息 */

      void main()

      /* 定義名為main 的函數(shù),它不接受參數(shù)值 */

      {

      /* main函數(shù)的語句都被括在花括號(hào)中 */

      printf(“hello, worldn”);

      /* main 函數(shù)調(diào)用庫(kù)函數(shù)printf 以顯示字符序列,其中n代表?yè)Q行符 */

      }

      第二章習(xí)題答案

      一、選擇題

      1~5:CBABB 6~10:CDCDD 11~15:CADBC 16~20:BDAAD

      二、填空題

      1、整型,實(shí)型,字符型,枚舉類型2、1 3、9 4、12353514 5、2,1 6、2,2 7、10 20 0

      8、a=14 9、2,3,1

      10、double

      第三章習(xí)題答案

      一、選擇題

      1~5:CBBBC 6~10:DDDBB

      二、填空題

      1、控制語句,表達(dá)式語句,復(fù)合語句

      2、;

      3、{} 4、1

      5、a

      6、c:dec=120,oct=170,hex=78,ASCII=x 7、32767,32767 8、10,A,10 9、3 3

      10、(1)123.456001

      (2)□□□□□□□ 123.456

      (3)123.4560

      (4)8765.456700

      (5)□□□□□□ 8765.457

      (6)8765.4567

      (7)8765.4567

      三、編程題

      1、參考答案:

      #include void main()

      {

      int a,b,c;

      long int u,n;

      float x,y,z;char c1,c2;

      a=3;b=4;c=5;

      x=1.2;y=2.4;z=-3.6;

      u=51274;n=128765;

      c1='a';c2='b';printf(“n”);

      printf(“a=%2d b=%2d

      c=%2dn”,a,b,c);

      printf(“x=%8.6f,y=%8.6f,z=%9.6fn”,x,y,z);

      printf(“x+y=%5.2f y+z=%5.2f z+x=%5.2fn”,x+y,y+z,z+x);

      printf(“u=%6ld n=%9ldn”,u,n);

      printf(“c1='%c' or %d(ASCII)n”,c1,c1);

      printf(“c2='%c' or %d(ASCII)n”,c2,c2);

      }

      2、參考答案:

      #include

      void main()

      {

      float a, b, c, t;

      printf(“please input a,b,c:n”);

      scanf(“%f, %f, %f”, &a, &b, &c);

      t=(a+b+c)/3;

      printf(“average of %6.2f、%6.2f and

      %6.2f }

      3、參考答案:

      #include main()

      {

      int R, d;

      float s;

      printf(”請(qǐng)輸入圓的半徑“);

      scanf(”%d“,&R);

      d=2*R;

      c=2*3.14159*R;

      printf(”d=%d,c=%fn“,d,c);

      }

      4、參考答案:

      #include void main()

      {

      int h, f, x, y;/* x為雞的數(shù)量,y為兔的數(shù)量 */ printf(”請(qǐng)輸入雞兔的總頭數(shù)h,總腳數(shù) f:“);

      scanf(”%d%d“, &h, &f);

      x=(4*h-f)/2;

      y=(f-2*h)/2;

      printf(”籠中有雞%d 只,有兔%d只。n“, x, y);is %6.2fn”,a,b,c,t);

      }

      第四章習(xí)題答案

      一、選擇題

      CDDDD CDBBC

      二、填空題

      1、&&,||,!,!,| |

      2、(y%2 0)3、1

      4、(a+b>c&&a+c>b&&b+c>a)5、2 3 3 6、7

      三、編程題

      1、參考答案:

      #include void main()

      { int x;

      scanf(“%d”,&x);

      if(x%5 0 && x%7 0)

      printf(“yesn”);else

      printf(“non”);

      }

      2、參考答案:

      #include void main()

      { int

      a, b, c, max;

      printf(“請(qǐng)輸入三個(gè)整數(shù):%%d%%d%%dn”);

      scanf(“%d%d%d”, &a, &b, &c);

      if(a>=b)

      if(a>=c)max=a;

      else max=c;

      else

      if(b>=c)max=b;

      else

      max=c;

      printf(“n 最大數(shù)為:%dn”,max);

      }

      3、參考答案:

      #include void main()

      {

      float

      x , y;

      printf(“請(qǐng)輸入x 的值:”);

      scanf(“%f”, &x);

      if(x<1)y=1;

      else if(x<10)

      y=2*x-1;

      else

      y=3*x-11;

      printf(“y = %.2fn”, y);

      }

      4、參考答案:

      #include void main()

      {

      int year;

      float money,rate,total;

      /* money:本金 rate:月利率 total:本利合計(jì)

      */

      printf(“Input money and year =?”);

      scanf(“%f%d”, &money, &year);

      /* 輸入本金和存款年限 */

      if(year 1)rate=0.00315;

      /* 根據(jù)年限確定利率 */

      else if(year 2)rate=0.00330;

      else if(year 3)rate=0.00345;else if(year 5)rate=0.00375;

      else if(year 8)rate=0.00420;

      else rate=0.0;

      total=money + money * rate * 12 * year;

      /* 計(jì)算到期的本利合計(jì) */

      printf(“ Total = %.2fn”, total);

      }

      第五章習(xí)題答案

      一、選擇題

      1~5: ACCBA 6~10:ACDCB

      二、填空題

      1、(1)i<=9 或 i<10(2)j%3!=0 2、7

      3、(1)ch=ch+

      1、(2)printf(“n”)

      三、編程題

      1、參考答案:

      #include void main()

      { int i=2;

      long p=1;

      do

      { p=p*i;

      i=i+2;

      } while(i<10);

      printf(“2*4*6*8=%ldn”,p);

      }

      2、參考答案:

      #include void main()

      {int n=0;

      char c;

      c=getchar();

      while(c!='n')

      { if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))n++;

      c=getchar();

      }

      printf(“%dn”,n);

      }

      3、參考答案:

      #include void main()

      {int a,max;

      scanf(“%d”,&a);max=a;while(a!=0)

      {scanf(“%d”,&a);

      if(max

      }

      printf(“%d”,max);

      }

      4、參考答案: #include void main()

      {

      int day = 0, buy = 2;

      float sum = 0.0, ave;do {

      sum += 0.8 * buy;

      day++;

      buy *= 2;

      }

      while(buy <= 100);

      ave = sum / day;

      printf(“%f”, ave);

      }

      5、參考答案: #include void main()

      { int f1,f2,f5,count=0;

      for(f5=0;f5<=20;f5++)

      for(f2=0;f2<=(100-f5*5)/2;f2++)

      { f1=100-f5*5-f2*2;

      if(f5*5+f2*2+f1 100)

      printf(“No.%2d >> 5: %4d 2: %4d 1: %4dn”,++count,f5,f2,f1);

      }

      printf(“共有%d 種換法”,count);

      }

      6、參考答案: #include void main()

      { int i,j,n;printf(“nPlease Enter n:”);

      scanf(“%d”,&n);

      for(i=1;i<=n;i++)

      { for(j=1;j<=n-i;j++)

      printf(“ ”);

      for(j=1;j<=2*i-1;j++)

      printf(“*”);

      printf(“n”);

      }

      }

      7、參考答案: #include void main()

      {

      int i, j;

      float g, sum, ave;

      for(i=1;i<=6;i++)

      {

      sum = 0;

      for(j=1;j<=5;j++)

      {

      scanf(“%f”, &g);sum += g;}

      ave = sum / 5;

      printf(“No.%d ave=%5.2fn”, i, ave);

      }

      }

      8、參考答案: #include void main()

      {int n,t,number=20;

      float a=2,b=1,s=0;

      for(n=1;n<=number;n++)

      {s=s+a/b;t=a;a=a+b;

      b=t;}

      printf(“s=%9.6fn”,s);

      } 第六章習(xí)題答案

      一、選擇題

      1~5:CBABD 6~10:CDBCD

      二、填空題

      1、庫(kù)函數(shù)(或系統(tǒng)函數(shù)),自定義函數(shù)

      2、無參函數(shù),有參函數(shù)

      3、傳值方式

      4、實(shí)參,形參5、1 3

      6、max is 2 7、15 8、1,2,3

      三、編程題

      1、參考答案:

      #include

      int is_prime(int a)

      { int i,p=1;

      for(i=2;i

      if(a%i 0)

      { p=0;break;}

      return(p);}

      void main()

      {int i=11;

      if(is_prime(i))

      printf(“1”);

      else

      printf(“0”);

      }

      2、參考答案:

      #include

      int gongyue(int num1,int num2)

      {int temp,a,b;

      if(num1 < num2)

      {temp=num1;num1=num2;num2=temp;}

      a=num1;

      b=num2;

      while(b)

      {temp=a%b;a=b;b=temp;}

      return(a);

      }

      void main()

      {int i=12,j=8;

      printf(“%d”,gongyue(i,j));

      }

      第七章習(xí)題答案

      一、選擇題

      1~5:BDDCC 6~10:CDCAB

      二、填空題

      1、字符、1 2、2

      3、c:win98cmd.exe 4、1,2,3,4,5,6,7,8,9,0 5、325678 6、1,0,7,0, 7、4332

      8、(1)j=2

      三、編程題

      1、參考答案:

      #include

      void main()

      { int i,a[20],s,count;

      s=count=0;

      for(i=0;i<20;i++)

      scanf(“%d”, &a[i]);

      for(i=0;i<20;i++)

      { if(a[i]<0)

      continue;

      s+=a[i];

      2)j>=i

      (count++;

      }

      printf(“s=%dt count=%dn”,s,count);

      }

      2、參考答案:

      #include void main()

      { int a[3][4],i,j,max;

      for(i=0;i<3;i++)

      for(j=0;j<4;j++)

      scanf(“%d”,&a[i][j]);

      max=a[0][0];

      for(i=0;i<3;i++)

      for(j=0;j<4;j++)

      if(a[i][j]>max)

      printf(“max=%dn”,max);

      }

      3、參考答案:

      #include void main()

      { int a[11]={3,4,7,9,10,13,14,15,18,20};

      int i,j,n;

      scanf(“%d”,&n);

      i=0;

      while(i<10)

      { if(n

      {

      for(j=10;j>i;j--)

      a[j]=a[j-1];

      a[i]=n;

      break;

      }

      i++;

      }

      if(i>=10)

      a[10]=n;

      for(i=0;i<11;i++)

      printf(“%4d”,a[i]);

      }

      第八章習(xí)題答案

      max=a[i][j];

      一、選擇題

      1?5 A B C C B 6?10 D A C B B 11?15 D A C C C

      二、填空題

      1.(1)*(2)&

      2.(1)*p(2)**a

      (3)2 3.10 4.*p>*s

      5.*(++p)

      三、編程題

      1.編程實(shí)現(xiàn)從鍵盤輸入一個(gè)字符串,將其字符順序顛倒后重新存放,并輸出這個(gè)字符串。

      #include

      #include

      void Inverse(char *pStr)?

      main()

      {

      char str[80]?

      printf(“Input a string:n”)?

      gets(str)?

      /*輸入字符串*/

      Inverse(str)?

      /*將存于 str 數(shù)組中的字符串逆序存放*/

      printf(“The inversed string is:n”)?

      puts(str)?

      /*輸出字符串*/

      }

      /*函數(shù)功能: 實(shí)現(xiàn)字符串逆序存放

      函數(shù)參數(shù): 字符指針變量,所指向的存儲(chǔ)單元存放源字符串,逆序后的字符串也存放于此

      返回值: 無*/

      void Inverse(char *pStr)

      {

      int len?

      char temp?

      char *pStart?

      /*指針變量 pStart 指向字符串的第一個(gè)字符*/

      char *pEnd?

      /*指針變量 pEnd指向字符串的最后一個(gè)字符*/

      len = strlen(pStr)?

      /*求出字符串長(zhǎng)度*/

      for(pStart=pStr,pEnd=pStr+len?1? pStart

      {

      temp = *pStart?

      *pStart = *pEnd?

      *pEnd = temp?

      }

      }

      2.從鍵盤任意輸入 10 個(gè)整數(shù),用函數(shù)編程實(shí)現(xiàn)計(jì)算最大值和最小值,并返回它們所在數(shù)組

      中的位置。

      #include

      int FindMax(int num[], int n, int *pMaxPos)?

      int FindMin(int num[], int n, int *pMinPos)? main()

      {

      int num[10], maxValue, maxPos, minValue, minPos, i?

      printf(“Input 10 numbers:n ”)?

      for(i=0? i<10? i++)

      {

      scanf(“%d”, &num[i])?

      /* 輸入 10 個(gè)數(shù)*/

      }

      maxValue = FindMax(num, 10, &maxPos)? /* 找最大值及其所在下標(biāo)位置 */

      minValue = FindMin(num, 10, &minPos)? /* 找最小值及其所在下標(biāo)位置 */

      printf(“Max=%d, Position=%d, Min=%d, Position=%dn”,maxValue, maxPos, minValue, minPos)?

      }

      /*函數(shù)功能:求 n個(gè)數(shù)中的最大值及其所在下標(biāo)位置

      函數(shù)入口參數(shù):整型數(shù)組 num,存儲(chǔ) n個(gè)整數(shù),整型變量 n,表示數(shù)組元素個(gè)數(shù)

      函數(shù)出口參數(shù):整型指針變量 pMaxPos,指向的地址單元存儲(chǔ)最大值在數(shù)組中的下標(biāo)位置

      函數(shù)返回值: 最大值*/

      int FindMax(int num[], int n, int *pMaxPos)

      {

      int i, max?

      max = num[0]?

      /*假設(shè) num[0]為最大*/

      *pMaxPos = 0?

      /*假設(shè)最大值在數(shù)組中的下標(biāo)位置為 0 */

      for(i = 1? i < n? i++)

      {

      if(num[i] > max)

      {

      max = num[i]?

      *pMaxPos = i?

      }

      }

      return max ? }

      /*函數(shù)功能: 求 n個(gè)數(shù)中的最小值及其所在下標(biāo)位置

      函數(shù)入口參數(shù): 整型數(shù)組 num,存儲(chǔ) n個(gè)整數(shù),整型變量 n,表示數(shù)組元素個(gè)數(shù)

      函數(shù)出口參數(shù): 整型指針變量 pMinPos,指向的地址單元存儲(chǔ)最小值在數(shù)組中的下標(biāo)位置

      函數(shù)返回值: 最小值*/

      int FindMin(int num[], int n, int *pMinPos)

      {

      int i, min?

      min = num[0]?

      /*假設(shè) num[0]為最小*/

      *pMinPos = 0?

      /*假設(shè)最小值在數(shù)組中的下標(biāo)位置為 0 */

      for(i = 1?i < 10?i++)

      {

      if(num[i] < min)

      {

      min = num[i]?

      *pMinPos = i?

      }

      }

      return min ?

      }

      3.將 5 個(gè)字符串從小到大排序后輸出。

      #include

      void main(void)

      { int i?

      char *pcolor[5]={ “red”, “blue”, “yellow”, “green”, “purple” }?

      void fsort(char *color[ ], int n)?

      fsort(pcolor, 5)?

      for(i = 0? i < 5? i++)

      printf(“%s ”, pcolor[i])?

      }

      void fsort(char *color[ ], int n)

      {

      int k, j?

      char *temp?

      for(k = 1? k < n? k++)

      for(j = 0? j < n?k? j++)

      if(strcmp(color[j],color[j+1])>0)

      {

      temp = color[j]?

      color[j] = color[j+1]?

      color[j+1]

      temp?

      }

      }

      4.編寫一個(gè)能對(duì)任意m×n階矩陣進(jìn)行轉(zhuǎn)置運(yùn)算的函數(shù) Transpose()。

      #include

      #define ROW 3

      #define COL 4

      void Transpose(int(*a)[COL], int(*at)[ROW], int row, int col)?

      void InputMatrix(int(*s)[COL], int row, int col)?

      void PrintMatrix(int(*s)[ROW], int row, int col)?

      main()

      {

      int s[ROW][COL]?

      /*s 代表原矩陣*/

      int st[COL][ROW]?

      /*st 代表轉(zhuǎn)置后的矩陣*/

      printf(“Please enter matrix:n”)?

      InputMatrix(s, ROW, COL)? /*輸入原矩陣,s 指向矩陣 s的第 0行,是行指針*/

      Transpose(s, st, ROW, COL)?/*對(duì)矩陣 s 進(jìn)行轉(zhuǎn)置,結(jié)果存放于 st 中*/

      printf(“The transposed matrix is:n”)?

      PrintMatrix(st, COL, ROW)? /*輸出轉(zhuǎn)置矩陣,*st 指向 st 的第 0 行,是行指針*/

      }

      /* 函數(shù)功能:對(duì)任意row行 col 列的矩陣轉(zhuǎn)置

      函數(shù)入口參數(shù):指向一維整型數(shù)組的指針變量a,指向單元存放轉(zhuǎn)置前的矩陣元素

      整型變量 row,矩陣的行數(shù)即二維整型數(shù)組的行數(shù)

      整型變量 col,矩陣的列數(shù)即二維整型數(shù)組的列數(shù)

      函數(shù)出口參數(shù):指向一維整型數(shù)組的指針變量at,指向單元存放轉(zhuǎn)置后的矩陣元素

      函數(shù)返回值: 無*/

      void Transpose(int(*a)[COL], int(*at)[ROW], int row, int col)

      {

      int i, j?

      for(i=0? i

      {

      for(j=0? j

      {

      *(*(at+j)+i)= *(*(a+i)+j)?

      }

      }

      }

      void InputMatrix(int(*s)[COL], int row, int col)

      /*輸入矩陣元素*/

      {

      int i, j?

      for(i=0? i

      {

      for(j=0? j

      {

      scanf(“%d”, *(s+i)+j)?

      /*這里*(s+i)+j 等價(jià)于&s[i][j]*/

      }

      }

      } void PrintMatrix(int(*s)[ROW], int row, int col)

      /*輸入矩陣元素*/

      {

      int i, j?

      for(i=0? i

      {

      for(j=0? j

      {

      printf(“%dt”, *(*(s+i)+j))? /*這里*(*(s+i)+j)等價(jià)于 s[i][j]*/

      }

      printf(“ n”)?

      }

      } 第九章習(xí)題答案

      一、選擇題

      1?5 B D D A C

      6?10 B C A D C

      二、填空題

      1.struct DATA d={2006,10,1}?

      2.sizeof(struct node)

      3.person[i].sex

      4.13431

      5.(1)struct node*(2)*s(3)p

      三、編程題

      1.定義一個(gè)能正常反映教師情況的結(jié)構(gòu)體 teacher,包含教師姓名、性別、年齡、所在部門和

      薪水; 定義一個(gè)能存放兩人數(shù)據(jù)的結(jié)構(gòu)體數(shù)組 tea,并用如下數(shù)據(jù)初始化:{{ “Mary “, ‘W’,40,‘Computer’ , 1234 },{“Andy“, ‘M’,55, ‘English’ , 1834}};要求:分別用結(jié)構(gòu)體數(shù)組 tea 和指針

      p輸出各位教師的信息,寫出完整定義、初始化、輸出過程。

      #include

      struct teacher

      { char name[8]?

      char sex?

      int age?

      char department[20]?

      float salary?

      } ?

      struct teacher tea[2]= {{“Mary ”, 'W',40, “Computer” , 1234 },{“Andy ”, 'M',55, “English” , 1834}} ?

      main()

      { int i?

      struct teacher *p?

      for(i=0?i<2?i++)

      printf(“%s,t%c,t%d,t%s,t%f”,tea[i].name,tea[i].sex,tea[i].age,tea[i].department,tea[i].salary)?

      for(p=tea?p

      printf(“%s,t%c,t%d,t%s,t%f”, p?>department, p?>salary)?

      }

      2.定義一個(gè)結(jié)構(gòu)體變量(包括年、月、日)。計(jì)算該日在本年中是第幾天,注意閏年問題。

      #include

      struct

      {int year?

      int month?

      int day?

      }date?

      main()

      {int days?

      printf(“Input year,month,day:”)?

      scanf(“%d,%D,%d”,&date.year,&date.month,&date.day)?

      switch(date.month)

      {case 1: days=date.day?

      break?

      case 2: days=date.day+31?

      break?

      case 3: days=date.day+59?

      break?

      case 4: days=date.day+90?

      break?

      case 5: days=date.day+120?

      break?

      case 6: days date.day+31?

      break?

      case 7: days=date.day+181?

      break?

      case 8: days=date.day+212?

      break?

      case 9: days date.day+243?

      break?

      case 10: days date.day+273?

      break?

      case11: days=date.day+304?

      break?

      case 12: days date.day+334?

      break?

      p?>name,p?>sex,p?>age,}

      if((date.year%4 0&&date.year%100!=0||date.year%400 0)&&date.month> 3)

      days+=1?

      printf(“n%d/%d is the %dth day in%d.”,date.month,date.day,days,date.year)?

      }

      3.構(gòu)建簡(jiǎn)單的手機(jī)通訊錄,手機(jī)通訊錄包括信息(姓名、年齡、聯(lián)系電話),要求實(shí)現(xiàn)新建、查詢功能。假設(shè)通信錄最多容納 50 名聯(lián)系人信息。

      #include

      #include

      /*手機(jī)通訊錄結(jié)構(gòu)定義*/

      struct friends_list{

      char name[10]?

      /* 姓名 */

      int age?

      /* 年齡 */

      char telephone[13]?

      /* 聯(lián)系電話 */

      }?

      int Count = 0?

      /* 定義全局變量 Count,記錄當(dāng)前聯(lián)系人總數(shù) */

      void new_friend(struct friends_list friends[ ])?

      void search_friend(struct friends_list friends[ ], char *name)? int main(void){

      int choice?

      char name[10]?

      struct friends_list friends[50]?

      /* 包含 50 個(gè)人的通訊錄 */

      do{

      printf(“手機(jī)通訊錄功能選項(xiàng):1:新建 2:查詢 0:退出n”)?

      printf(“請(qǐng)選擇功能:”)?

      scanf(“%d”, &choice)?

      switch(choice){

      case 1:

      new_friend(friends)?

      break?

      case 2:

      printf(“請(qǐng)輸入要查找的聯(lián)系人名:”)?

      scanf(“%s”, name)?

      search_friend(friends, name)?

      break?

      case 0: break?

      }

      }while(choice!= 0)?

      printf(“謝謝使用通訊錄功能!n”)?

      return 0?

      }

      /*新建聯(lián)系人*/

      void new_friend(struct friends_list friends[ ])

      {

      struct friends_list f?

      if(Count

      50){

      printf(“通訊錄已滿!n”)?

      return?

      }

      printf(“請(qǐng)輸入新聯(lián)系人的姓名:”)?

      scanf(“%s”, f.name)?

      printf(“請(qǐng)輸入新聯(lián)系人的年齡:”)?

      scanf(“%d”, &f.age)?

      printf(“請(qǐng)輸入新聯(lián)系人的聯(lián)系電話:”)?

      scanf(“%s”, f.telephone)?

      friends[Count] = f?

      Count++?

      }

      /*查詢聯(lián)系人*/

      void search_friend(struct friends_list friends[ ], char *name)

      {

      int i, flag = 0?

      if(Count

      0){

      printf(“通訊錄是空的!n”)?

      return?

      }

      for(i = 0? i < Count? i++)

      if(strcmp(name,friends[i].name)

      0){

      /* 找到聯(lián)系人*/

      flag=1?

      break?

      }

      if(flag){

      printf(“姓名: %st”, friends[i].name)?

      printf(“年齡: %dt”, friends[i].age)?

      printf(“電話: %sn”, friends[i].telephone)?

      }

      else

      printf(“無此聯(lián)系人!”)?

      }

      4.建立一個(gè)教師鏈表,每個(gè)結(jié)點(diǎn)包括學(xué)號(hào)(no),姓名(name[8]),工資(wage),寫出動(dòng)態(tài)創(chuàng)建

      函數(shù) creat 和輸出函數(shù) print。

      #include

      #include

      #define NULL 0

      #define LEN sizeof(struct teacher)

      struct teacher

      {int no?

      char name[8]?

      float wage?

      struct teacher * next?

      }?

      int n?

      struct teacher *creat(void)

      { struct teacher *head?

      struct teacher *p1,*p2?

      n=0?

      p1=p2=(struct teacher *)malloc(LEN)?

      scanf(“%d%s%f”,&p1?>no,p1?>name, &p1?>wage)?

      head=NULL?

      while(p1?>no!=0)

      { n=n+1?

      if(n 1)head p1?

      else p2?>next p1?

      p2=p1?

      p1=(struct teacher *)malloc(LEN)?

      scanf(“%d%s%f”,&p1?>no,p1?>name, &p1?>wage)?

      }

      p2?>next=NULL?

      return(head)?

      }

      void print(struct teacher *head)

      { struct teacher *p?

      p=head?

      if(head!=NULL)

      do{

      printf(“%dt%st%fn”, p?>no, p?>name, p?>wage)?

      p=p?>next?

      } while(p!=NULL)?

      }

      5.在上一題基礎(chǔ)上,假如已經(jīng)按學(xué)號(hào)升序排列,寫出插入一個(gè)新教師的結(jié)點(diǎn)的函數(shù) insert。

      struct teacher insert(struct teacher *head,struct teacher *tea)

      { struct teacher *p0,*p1,*p2?

      p1=head?

      p0=tea?

      if(head=NULL)

      {head=p0? p0?>next=NULL?}

      else

      while((p0?>no>p1?>no)&&(p1?>next!=NULL))

      { p2=p1?

      p1=p1?>next?}

      if(p0?>no< p1?>no)

      { if(head p1)

      head=p0?

      else

      { p2?>next p0?

      p0?>next p1?

      }

      else

      { p1?>next p0?p0?>next=NULL?}

      n=n+1?

      return(head)?

      }

      第二篇:C語言課后實(shí)驗(yàn)答案

      #include using namespace std;int main(){ cout<<“Hello World!”< using namespace std;int main(){ int p,q,r;cout<<“please input two intergers:”<>p>>q;if(p>q){

      r=p;

      p=q;

      q=r;} r=p%q;while(r!=0){p=q;q=r;r=p%q;} cout<<“the maximun common divisor is”<

      #include using namespace std;int main(){ double a,b,c;cout<<“please input two numbers:”;

      } cin>>a>>b;c=a+b;cout<

      #include using namespace std;int main(){ char name1[41],name2[41];cout<

      cin>>name1;cout<>name2;cout<

      #include #include using namespace std;int main(){

      } double a,b;double h;double sum;int n;int i;a=0.0;b=1.0;n=1000;h=(b-a)/n;sum=(sin(a)+sin(b))/2;for(i=1;i

      #include using namespace std;double grav(double m1,double m2,double distance){ double g,G=6.67E-11;g=G*m1*m2/(distance*distance);return g;} int main(){ double Gse,Gme,Msun,Mearth,Mmoon,Dme;Msun=1.987E30;Mearth=5.975E24;Gse=grav(Msun,Mearth,1.495E11);cout<<“the gravitation between sun and earth is”< #include using namespace std;int main(){ double a,b,c,s,area;cout<<“please input a,b,c=”;cin>>a>>b>>c;s=(a+b+c)/2;area=sqrt(s*(s-a)*(s-b)*(s-c));cout<<“area=”< #include using namespace std;int main(){ double a,b,c,s,delta,p,q;cout<<“please input a,b,c=”;cin>>a>>b>>c;delta=b*b-4*a*c;p=-b/(2*a);q=sqrt(fabs(delta))/(2*a);if(delta>=0)

      cout<<“x1=”<

      cout<<“x1=”<

      cout<#include using namespace std;int main(){ double c,f;cout<<“請(qǐng)輸入一個(gè)華氏溫度:”;cin>>f;c=5.0/9.0*(f-32);cout<<“對(duì)應(yīng)的華氏溫度”<

      #include using namespace std;int main(){ unsigned int n;char c1,c2,c3,c4;cout<<“請(qǐng)輸入一個(gè)界于1000與9999之間的數(shù):”;cin>>n;cout<<“反序輸出前的數(shù)為:”<

      #include using namespace std;int main(){ char ch;cout<<“請(qǐng)輸入一個(gè)字母:”;cin>>ch;if(ch>='A'&&ch<='Z')

      ch=ch-'A'+'a';cout<<“將大寫轉(zhuǎn)換為小寫后,該字母為:”< using namespace std;int main(){ int change;cout<<“請(qǐng)輸入要找給顧客的零錢(以分為單位):”;cin>>change;cout<<“找給顧客的5角硬幣個(gè)數(shù)為:”<

      #include using namespace std;int main(){ int a[7];

      cout<<“please input an array with seven elements:”<

      cin>>a[i];int big=a[0];for(int j=0;j<7;j++)

      if(a[j]>big)

      big=a[j];

      cout<<“max=”<

      return 0;}

      #include using namespace std;int main(){ int M[5][5];int i,j;for(i=0;i<5;i++){ for(j=0;j<5;j++)M[i][j]=0;M[i][i]=1;} for(i=0;i<5;i++){

      for(j=0;j<5;j++)

      cout<

      cout<

      #include using namespace std;int mystrlen(char string[]){ int len=0;while(string[len]!='