當前位置:首頁 » 編程語言 » c語言程序設計完整答案
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言程序設計完整答案

發布時間: 2023-02-09 04:58:50

A. c語言程序設計 答案

A
**0**
**2**
C
同學,你是在問題,還是在對題,還是在??
你具體不懂什麼呢。
這些都是簡單的循環類,條件類。
比如說switch
中的break對switch有效,遇到break,則就近的switch跳出。
continue只對循環有效,而對switch無效。

還有if
else
是選擇結構的,即選擇了if,則執行if後的語句,else部分的不看。
還比如說++a和a++
前者先自增,後使用,後者先使用,後自增。

再比如說變數的使用范圍,即從定義處往下就是他的作用域。
有靜態的,具備繼承性 static
有擴展的,當你在別的函數中也想使用下面定義的變數時,就可以用extern
還有局部的,在一個函數中的a,與另一個函數中的a,此a非彼a
當變數定義在符合語句里時,他的作用域僅僅局限於此復合語句。。其他同名變數,並非此變數。

請問還有什麼不懂的么。

B. c語言程序設計答案

只說一下思路
實在寫不出來再追問
最好能自己解決
第一題:
就是一個楊輝三角問題
用雙循環
外循環是行數(用
i
表示)
從0到n
(n自己輸入)
內循環是列數(用
j
表示)
從0到2*i-1
然後就是賦

很多種方式
比如你定義一個
字元變數
C
給它賦值為A
然後每次都用C給數組賦值
然後讓C加1
方法很多
(數組是字元二維數組,

之前要初始化一下
給數組都賦值為
空格)
第二題:
定義兩個二維數組
一個一維數組
按照題目要求
先把每個同學的成績和名字分別存放到兩個二維數組裡面
同樣是雙循環
然後再用雙循環
把每個同學成績加起來放到一維數組裡面
然後接下來就是對一位數組內容進行排序
排序過程中
也要將名字的那個二維數
組同樣排序
因為一維數組中的總分順序和二維數組中的姓名順序是一樣的
比如
要將第二個同學的成績和第五個同學的成績交換
那麼就要
將總分交換
再將姓名交換
不然分就不對人了
第三題:
題目沒明白什麼意思
第四題:
用循環從第一個元素判斷到最後一個元素
定義4個變數存儲
數字
大寫
小寫
空格出現的次數
查一下ASCII碼
數字好像是48-57
大寫字母是
65-90
小寫是
97-122
判斷元素內容的ASCII在哪個范圍
哪個變數就加1

C. 求C語言程序設計的答案

a==b表示判斷a和b是否相等,後面沒輸出結果!

a=b是將b的值賦給a,後面輸出「*****」

D. 急求C語言程序設計答案!題目如下(兩道題)!!重金答謝!回答運行正確可加賞金。在線等高手江湖救急!

第一題:首先值得說明的是,你的題目有點兒問題應該是: if(a[i][j]>a[row][colum]){row=i;colum=j;}
然後,答案是:row
a[row][colum]

第二題:素數的問題,也就是質數,解題思路就是,如果這個數不能夠被2~這個數的開根號整除的話,那麼這個數就是素數。
【蒼狼涯】的答案是正確的。
我修改一下。
如下:
#include<stdio.h>
#include<math.h>
bool IsPrime(int x);
int main()
{
int num[5]={0,0,0,0,0};

int temp=0;
for(int i=1000;i>=2;i--)
{
if (IsPrime(i))
{
num[temp]=i;
temp++;
if (temp==5)
break;
}
}

printf("結果如下:\n");
for (int k=0;k<5;k++)
{
printf("%d\t",num[k]);
}
printf("\n");
return 0;
}
bool IsPrime(int x)
{
for(int i = 2; i <= (int)sqrt(x); i++)
{
if((x % i) == 0)
return false;
}

return true;
}

E. C語言程序設計教程答案~有追加懸賞100分!

1 【C語言】《C語言程序設計教程(第二版)》習題答案

說 明
1. 本文所指的《C語言程序設計教程(第二版)》是李鳳霞主編、北京理
工大學出版社出版的,綠皮。

2 第1章 程序設計基礎知識
一、單項選擇題(第23頁)
1-4.CBBC 5-8.DACA

二、填空題(第24頁)
1.判斷條件 2.面向過程編程 3.結構化 4.程序 5.面向對象的程序設計語言 7.有窮性 8.直到型循環 9.演算法 10.可讀性 11.模塊化 12.對問題的分析和模塊的劃分

三、應用題(第24頁)
2.源程序:
main()
{int i,j,k; /* i:公雞數,j:母雞數,k:小雞數的1/3 */
printf("cock hen chick\n");
for(i=1;i<=20;i++)
for(j=1;j<=33;j++)
for(k=1;k<=33;k++)
if (i+j+k*3==100&&i*5+j*3+k==100)
printf(" %d %d %d\n",i,j,k*3);}
執行結果:
cock hen chick
4 18 78
8 11 81
12 4 84
3.現計算斐波那契數列的前20項。
遞推法 源程序:
main()
{long a,b;int i;
a=b=1;
for(i=1;i<=10;i++) /*要計算前30項,把10改為15。*/
{printf("%8ld%8ld",a,b);
a=a+b;b=b+a;}}
遞歸法 源程序:
main()
{int i;
for(i=0;i<=19;i++)
printf("%8d",fib(i));}
fib(int i)
{return(i<=1?1:fib(i-1)+fib(i-2));}
執行結果:
1 1 2 3 5 8 13 21 34 55
89 144 233 377 610 987 1597 2584 4181 6765
4.源程序:
#include "math.h";
main()
{double x,x0,deltax;
x=1.5;
do {x0=pow(x+1,1./3);
deltax=fabs(x0-x);
x=x0;
}while(deltax>1e-12);
printf("%.10f\n",x);}
執行結果:
1.3247179572
5.源程序略。(分子、分母均構成斐波那契數列)
結果是32.66026079864
6.源程序:
main()
{int a,b,c,m;
printf("Please input a,b and c:");
scanf("%d %d %d",&a,&b,&c);
if(a<b){m=a;a=b;b=m;}
if(a<c){m=a;a=c;c=m;}
if(b<c){m=b;b=c;c=m;}
printf("%d %d %d\n",a,b,c);}
執行結果:
Please input a,b and c:123 456 789
789 456 123
7.源程序:
main()
{int a;
scanf("%d",&a);
printf(a%21==0?"Yes":"No");}
執行結果:
42
Yes

3 第2章 C語言概述
一、單項選擇題(第34頁)
1-4.BDCB 5-8.AABC

二、填空題(第35頁)
1.主 2.C編譯系統 3.函數 函數 4.輸入輸出 5.頭 6. .OBJ 7.庫函數 8.文本

三、應用題(第36頁)
5.sizeof是關鍵字,stru、_aoto、file、m_i_n、hello、ABC、SIN90、x1234、until、cos2x、s_3是標識符。
8.源程序:
main()
{int a,b,c;
scanf("%d %d",&a,&b);
c=a;a=b;b=c;
printf("%d %d",a,b);}
執行結果:
12 34
34 12

4 第3章 數據類型與運算規則
一、單項選擇題(第75頁)
1-5.DBACC 6-10.DBDBC 11-15.ADCCC 16-20.CBCCD 21-25.ADDBC 26-27.AB

二、填空題(第77頁)
1.補碼 2.±(10^-308~10^308) 3.int(整數) 4.單目 自右相左 5.函數調用 6.a或b 7.1 8.65,89

三、應用題(第78頁)
1.10 9
2.執行結果:
11
0
0
12
1

5 第4章 順序結構程序設計
一、單項選擇題(第90頁)
1-5.DCDAD 6-10.BACBB

二、填空題(第91頁)
1.一 ;2. 5.169000 3.(1)-2002500 (2)I=-200,j=2500 (3)i=-200
j=2500 4.a=98,b=765.000000,c=4321.000000 5.略 6.0,0,3 7.3 8.scanf("%lf%lf%lf",&a,&b,&c); 9. 13 13.000000,13.000000 10.a=a^c;c=c^a;a=a^c;(這種演算法不破壞b的值,也不用定義中間變數。)

三、編程題(第92頁)
1.仿照教材第27頁例2-1。
2.源程序:
main()
{int h,m;
scanf("%d:%d",&h,&m);
printf("%d\n",h*60+m);}
執行結果:
9:23
563
3.源程序:
main()
{int a[]={-10,0,15,34},i;
for(i=0;i<=3;i++)
printf("%d\370C=%g\370F\t",a[i],a[i]*1.8+32);}
執行結果:
-10℃=14°F 0℃=32°F 15℃=59°F 34℃=93.2°F
4.源程序:
main()
{double pi=3.14159265358979,r=5;
printf("r=%lg A=%.10lf S=%.10lf\n",r,2*pi*r,pi*pi*r);}
執行結果:
r=5 A=31.4159265359 S=49.3480220054
5.源程序:
#include "math.h";
main()
{double a,b,c;
scanf("%lf%lf%lf",&a,&b,&c);
if (a+b>c&&a+c>b&&b+c>a)
{double s=(a+b+c)/2;
printf("SS=%.10lf\n",sqrt(s*(s-a)*(s-b)*(s-c)));}
else printf("Data error!");}
執行結果:
4 5 6
SS=9.9215674165
6.源程序:
main()
{int a=3,b=4,c=5;float d=1.2,e=2.23,f=-43.56;
printf("a=%3d,b=%-4d,c=**%d\nd=%g\ne=%6.2f\nf=%-10.4f**\n",a,b,c,d,e,f);}
7.源程序:
main()
{int a,b,c,m;
scanf("%d %d %d",&a,&b,&c);
m=a;a=b;b=c;c=m;
printf("%d %d %d\n",a,b,c);}
執行結果:
5 6 7
6 7 5
8.源程序:
main()
{int a,b,c;
scanf("%d %d %d",&a,&b,&c);
printf("average of %d,%d and %d is %.2f\n",a,b,c,(a+b+c)/3.);
執行結果:
6 7 9
average of 6,7 and 9 is 7.33
9.不能。修改後的源程序如下:
main()
{int a,b,c,x,y;
scanf("%d %d %d",&a,&b,&c);
x=a*b;y=x*c;
printf("a=%d,b=%d,c=%d\n",a,b,c);
printf("x=%d,y=%d\n",x,y);}

6 第5章 選擇結構程序設計
一、單項選擇題(第113頁)
1-4.DCBB 5-8.DABD

二、填空題(第115頁)
1.非0 0 2.k==0
3.if (abs(x)>4) printf("%d",x);else printf("error!");
4.if((x>=1&&x<=10||x>=200&&x<=210)&&x&1)printf("%d",x);
5.k=1 (原題最後一行漏了個d,如果認為原題正確,則輸出k=%。)
6. 8! Right!11 7.$$$a=0 8.a=2,b=1

三、編程題(第116頁)
1.有錯。正確的程序如下:
main()
{int a,b,c;
scanf("%d,%d,%d",&a,&b,&c);
printf("min=%d\n",a>b?b>c?c:b:a>c?c:a);}
2.源程序:
main()
{unsigned long a;
scanf("%ld",&a);
for(;a;printf("%d",a%10),a/=10);}
執行結果:
12345
54321
3.(1)源程序:
main()
{int x,y;
scanf("%d",&x);
if (x>-5&&x<0)y=x;
if (x>=0&&x<5)y=x-1;
if (x>=5&&x<10)y=x+1;
printf("%d\n",y);}
(2)源程序:
main()
{int x,y;
scanf("%d",&x);
if(x<10) if(x>-5) if(x>=0) if(x>=5)y=x+1;
else y=x-1; else y=x;
printf("%d\n",y);}
(3)源程序:
main()
{int x,y;
scanf("%d",&x);
if(x<10) if(x>=5)y=x+1;
else if(x>=0)y=x-1;
else if(x>-5)y=x;
printf("%d\n",y);}
(4)源程序:
main()
{int x,y;
scanf("%d",&x);
switch(x/5)
{case -1:if(x!=-5)y=x;break;
case 0:y=x-1;break;
case 1:y=x+1;}
printf("%d\n",y);}
4.本題為了避免考慮每月的天數及閏年等問題,故採用面向對象的程序設計。
現給出Delphi源程序和C++ Builder源程序。
Delphi源程序:
procere TForm1.Button1Click(Sender: TObject);
begin
edit3.Text:=format('%.0f天',[strtodate(edit2.text) -strtodate(edit1.text)]);
end;
procere TForm1.FormCreate(Sender: TObject);
begin
Edit2.Text:=datetostr(now);
button1click(form1)
end;
C++ Builder源程序:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Edit3->Text=IntToStr(StrToDate(Edit2->Text)-StrToDate(Edit1->Text))+"天";
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Edit2->Text=DateToStr(Now());
Button1Click(Form1);
}
執行結果:(運行於Windows下) http://img378.photo.163.com/nxgt/41463572/1219713927.jpg

5.源程序:
main()
{unsigned a,b,c;
printf("請輸入三個整數:");
scanf("%d %d %d",&a,&b,&c);
if(a&&b&&c&&a==b&&a==c)printf("構成等邊三角形\n");
else if(a+b>c&&a+c>b&&b+c>a)
if(a==b||a==c||b==c)printf("構成等腰三角形\n");
else printf("構成一般三角形\n");
else printf("不能構成三角形\n");}
執行結果:
請輸入三個整數:5 6 5
構成等腰三角形
6.源程序:
main()
{int x,y;
scanf("%d",&x);
if(x<20)y=1;
else switch(x/60)
{case 0:y=x/10;break;
default:y=6;}
printf("x=%d,y=%d\n",x,y);}
7.源程序:
main()
{unsigned m;float n;
scanf("%d",&m);
if(m<100)n=0;
else if(m>600)n=0.06;
else n=(m/100+0.5)/100;
printf("%d %.2f %.2f\n",m,m*(1-n),m*n);}
執行結果:
450
450 429.75 20.25
8. 2171天(起始日期和終止日期均算在內)
本題可利用第4小題編好的程序進行計算。把起始日期和終止日期分別打入「生日」和「今日」欄內,單擊「實足年齡」按鈕,將所得到的天數再加上1天即可。
9.源程序:
#include "math.h";
main()
{unsigned long i;
scanf("%ld",&i);
printf("%ld %d\n",i%10,(int)log10(i)+1);}
執行結果:
99887
7 5
10.源程序:
main()
{unsigned long i;unsigned j[10],m=0;
scanf("%ld",&i);
for(;i;){j[m++]=(i+2)%10;i/=10;}
for(;m;m--)i=i*10+j[m-1];
printf("%ld\n",i);}
執行結果:
6987
8109
(註:要加密的數值不能是0或以0開頭。如果要以0開頭需用字元串而不能是整數。)

7 第6章 循環結構程序設計
一、單項選擇題(第142頁)
1-4.BCCB 5-8.CBCA

二、填空題(第143頁)
1.原題可能有誤。如無誤,是死循環 2.原題有誤。如果把b=1後面的逗號改為分號,則結果是8。 3.20 4.11 5. 2.400000 6.*#*#*#$ 7.8 5 2 8.①d=1.0 ②++k ③k<=n 9.①x>=0 ②x<amin

三、編程題(第145頁)
1. 源程序:
main()
{int i=1,sum=i;
while(i<101){sum+=i=-i-2;sum+=i=-i+2;}
printf("%d\n",sum);}
執行結果:
51
2.源程序:
main()
{double p=0,n=0,f;int i;
for(i=1;i<=10;i++)
{scanf("%lf",&f);
if (f>0)p+=f; else n+=f;}
printf("%lf %lf %lf\n",p,n,p+n);}
3.源程序:
main()
{unsigned a;
scanf("%ld",&a);
for (;a;printf("%d,",a%10),a/=10);
printf("\b \n");}
執行結果:
23456
6,5,4,3,2
4.源程序:
main()
{unsigned long a,b,c,i;
scanf("%ld%ld",&a,&b);
c=a%1000;
for(i=1;i<b;i++)c=c*a%1000;
if(c<100)printf("0");
if(c<10)printf("0");
printf("%ld\n",c);}
執行結果:
129 57
009
5.略
6.原題提供的計算e的公式有誤(前面漏了一項1)。正確的公式是e= 1 + 1 + 1/2! + 1/3! + … + 1/n! + …
(1)源程序:
main()
{double e=1,f=1;int n;
for(n=1;n<=20;n++){f/=n;e+=f;}
printf("e=%.14lf\n",e);}
執行結果:
e=2.71828182845905
(2)源程序:
main()
{double e=1,f=1;int n;
for(n=1;f>1e-4;n++){f/=n;e+=f;}
printf("e=%.4f\n",e);}
執行結果:
e=2.7183
7.源程序:
main()
{unsigned long a=0,b=1,c=0;int i,d;
scanf("%d",&d);
for (i=1;i<=(d+2)/3;i++)
printf("%10ld%10ld%10ld",a,b,(a+=b+c,b+=c+a,c+=a+b));}
本題還可以用遞歸演算法(效率很低),源程序如下:
unsigned long fun(int i)
{return i<=3?i:fun(i-1)+fun(i-2)+fun(i-3);}
main()
{int i,d; scanf("%d",&d);
for(i=1;i<=d;i++)
printf("%10ld",fun(i));}
執行結果:
15
1 2 3 6 11 20 37 68
125 230 423 778 1431 2632 4841
8.源程序:
main()
{int i;
for(i=1010;i<=9876;i+=2)
if(i/100%11&&i%100%11&&i/10%100%11&&i/1000!=i%10&&i/1000!=i/10%10&&i/100%10!=i%10)printf(" %d",i);}
執行結果:
1024 1026 1028 1032 1034 1036 …… …… 9874 9876
9.源程序:
main()
{int i,j,k;
printf("apple watermelon pear\n");
for(i=1;i<=100;i++)
for(j=1;j<=10;j++)
if((k=100-i-j)*2==400-i*4-j*40)
printf("%4d%7d%9d\n",i,j,k);}
執行結果:
apple watermelon pear
5 5 90
24 4 72
43 3 54
62 2 36
81 1 18
10.源程序:
#include "stdio.h";
#define N 4 /* N為階數,可以改為其他正整數 */
main()
{int m=N*2,i,j;
for(i=1;i<m;printf("\n"),i++)
for(j=1;j<m;
putchar(N-abs(i-N)<=abs(j++-N)?' ':'*'));}
如果把N值改為5,則執行結果如下:
*
***
*****
*******
*********
*******
*****
***
*

作者:寧西貫通 2006-5-7 23:41 回復此發言

--------------------------------------------------------------------------------

8 說明
注意:上面最後一題的輸出結果應該是由星號組成的一個菱形,

9 第7章 數 組
一、單項選擇題(第192頁)
1-4.BBCC 5-8.AABA

二、填空題(第194頁)
1.1
2
4
8
16
32
64
128
256
512
2. ①a[age]++ ②i=18;i<26
3. ①break ②i==8
4. ①a[i]>b[j] ②i<3 ③j<5
5. ①b[j]=a[j][0] ②b[j]<a[j][k] 6.a[k++]=a[j]

三、編程題(第196頁)
1.源程序:
main()
{int a[4][4],i,j,s=0;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
scanf("%d",&a[i][j]);
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(i==j||i+j==3)s+=a[i][j];
printf("%d\n",s);} /* 注:5×5矩陣不能照此計算! */
執行結果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
68
2. 源程序:
main()
{int i,a[36];
a[0]=2;
for(i=1;i<=29;i++)a[i]=a[i-1]+2;
for(;i<=35;i++)a[i]=a[(i-30)*5+2];
for(i=0;i<=35;i++)printf("%d\t",a[i]);}
執行結果:
2 4 6 8 10 12 14 16 18 20
22 24 26 28 30 32 34 36 38 40
42 44 46 48 50 52 54 56 58 60
6 16 26 36 46 56
3. 源程序:
#include "stdlib.h"
#include "time.h"
main()
{int a[30],i,m=0;
randomize();
for(i=0;i<=29;i++)
{a[i]=rand();
if(m<a[i])m=a[i];
printf("%d\t",a[i]);}
for(i=0;i<=29;i++)if(a[i]==m)a[i]=-1;
printf("\n-----------------\n");
for(i=0;i<=29;i++)
if(~a[i])printf("%d\t",a[i]);
printf("\n");}
執行結果:
20679 29377 18589 9034 27083 4959 3438 5241 32278 23344
32499 29305 22340 5927 13031 2161 2583 31855 22977 14283
4851 22038 6992 11394 20887 27381 6293 18347 16414 10210
-----------------
20679 29377 18589 9034 27083 4959 3438 5241 32278 23344
29305 22340 5927 13031 2161 2583 31855 22977 14283 4851
22038 6992 11394 20887 27381 6293 18347 16414 10210
4.源程序:
main()
{int i,n=0,b[16];
scanf("%d",&i);
for(;i;i>>=1)b[n++]=i&1;
for(;n;)printf("%d",b[--n]);}
執行結果:
9876
10011010010100
本題也可以不用數組。源程序如下:
#include "stdio.h"
main()
{int i,n;
scanf("%d",&i);
for(n=16;n;n--)
{asm ROL i,1
putchar(i&1|48);}
} /* ROL是循環左移的匯編指令 */
5. 源程序:
#include "stdlib.h"
#include "time.h"
#define M 5
#define N 6
main()
{int a[M][N],i,j,t[M];
randomize();
/*生成M行N列隨機數*/
for(i=0;i<M;printf("\n"),t[i++]=0)
for(j=0;j<N;j++)
printf("%4d",a[i][j]=random(50));
/*找出每行的最小數,t[M]是第M行的最小數所在的列數*/
for(i=0;i<M;i++)
for(j=0;j<N;j++)
if(a[i][t[i]]>a[i][j])t[i]=j;
/*比較每個最小數在其所在的列上是否也是最小*/
for(j=0;j<M;j++)
for(i=0;i<M;i++)
{if(i==j)continue;
if(a[j][t[j]]>a[i][t[j]])
{t[j]=-1;break;}
}
printf("-------------------\n");
/*輸出在行和列上均為最小的數*/
for(i=0;i<M;i++)
if(t[i]!=-1)
printf("a[%d,%d]=%d\n",i,t[i],a[i][t[i]]);
}
執行結果:
13 19 13 20 0 1
20 41 6 16 35 30
3 5 37 8 23 15
6 36 24 29 18 1
1 5 28 21 46 34
-------------------
a[0,4]=0
a[1,2]=6
a[3,5]=1
a[4,0]=1
6. 源程序:
#include "stdlib.h"
#include "time.h"
#define M 5
#define N 7
main()
{int a[M][N],i,j,t=0;
randomize();
for(i=0;i<M;i++)
{a[i][N-1]=0;
for(j=0;j<N-1;j++)
{printf("%4d",a[i][j]=random(91)+10);
a[i][N-1]+=a[i][j];}
printf("%4d\n",a[i][N-1]);}
for(i=1;i<M;i++)
if(a[i][N-1]>a[t][N-1])t=i;
if(t)for(j=0;j<N;j++)
{i=a[0][j];a[0][j]=a[t][j];a[t][j]=i;}
printf("-----------------\n");
for(i=0;i<M;printf("\n"),i++)

10 第7章 數 組
for(j=0;j<N;j++)
printf("%4d",a[i][j]);
}
執行結果:
89 17 32 95 35 20 288
39 48 22 27 73 22 231
51 87 39 71 84 46 378
84 94 97 77 27 26 405
69 50 56 89 37 46 347
-----------------
84 94 97 77 27 26 405
39 48 22 27 73 22 231
51 87 39 71 84 46 378
89 17 32 95 35 20 288
69 50 56 89 37 46 347
7. 源程序:
#include "stdlib.h"
#include "time.h"
#define M 5
#define N 6
main()
{int a[M][N],i,j;
struct data{int value,x,y;}max,min;
max.value=0;min.value=100;
randomize();
for(i=0;i<M;printf("\n"),i++)
for(j=0;j<N;j++)
{printf("%4d",a[i][j]=random(100)+1);
if(max.value<a[i][j])
{max.value=a[i][j];max.x=i;max.y=j;}
if(min.value>a[i][j])
{min.value=a[i][j];min.x=i;min.y=j;}
}
printf("-----------------\n");
i=a[0][N-1];a[0][N-1]=max.value;a[max.x][max.y]=i;
i=a[M-1][0];a[M-1][0]=min.value;a[min.x][min.y]=i;
for(i=0;i<M;printf("\n"),i++)
for(j=0;j<N;j++)
printf("%4d",a[i][j]);
}
執行結果:
51 53 74 65 30 40
30 26 50 6 61 27
47 16 54 58 76 19
57 74 44 92 71 48
73 57 60 32 73 67
-----------------
51 53 74 65 30 92
30 26 50 73 61 27
47 16 54 58 76 19
57 74 44 40 71 48
6 57 60 32 73 67
9. 源程序:
main()
{char s[255];int i,j,b=1;
printf("Input a string:");
scanf("%s",s);
i=strlen(s);
for(j=1;j<=i/2;j++)
b=b&&(s[j-1]==s[i-j]);
printf(b?"Yes\n":"No\n");}
執行結果:
Input a string:level
Yes
10. 源程序:
main()
{char s[255],t,max=0,min=0,l,i;
printf("Input a string(length>4):");
gets(s);
l=strlen(s);
for(i=0;i<l;i++)
{if(s[max]<s[i])max=i;if(s[min]>s[i])min=i;}
t=s[1];s[1]=s[max];s[max]=t;if(min==1)min=max;
t=s[l-2];s[l-2]=s[min];s[min]=t;
printf("%s\n",s);}
執行結果:
Input a string(length>4):C++Builder
Cu+Beild+r
11. 源程序:
main()
{char m[13][10]={"****","January","February","March",
"April","May","June","July","August","September",
"October","November","December"};
int i,j,k,a,s,n;
printf("Please input an integer(100..999):");
scanf("%d",&n);
printf("%d:%d+%d+%d=%d, %d%%13=%d, %s\n", n,i,j,k,s,s,a,m[a=((s=(i=n/100)+(j=n/10%10)+(k=n%10))%13)]);}
執行結果:
Please input an integer(100..999):539
539:5+3+9=17, 17%13=4, April

11 第8章 函 數
一、單項選擇題(第241頁)
1-5.BCCAA 6-10.CCDDD 11-15.ACACB

二、填空題(第243頁)
1.看不出原題的意圖。因為要計算1~n的累加和,n應是一個≥1的正整數。可是題目中卻出現了n=0的情況。除非另加規定當n=0時1~n的累加和為0,或者把原題中的計算式改為計算0~n的累加和。據此猜測,原題應填為:①return(0) ②return(n+sum(n-1))
根據題意,如下程序較為合理:
int sum(int n)
{if(n<=0)return(-1); /* -1是出錯標志 */
else if(n==1)return(1);
else return(n+sum(n-1));}
2. ①return(1) ②return(n*facto(n-1))

三、編程題(第244頁)
3.源程序:
main()
{int i,a,b,c;
for(i=100;i<999;i++)
if((a=i/100)*a*a+(b=i/10%10)*b*b+(c=i%10)*c*c==i)
printf("%d\t",i);}
執行結果:
153 370 371 407
8.源程序(非遞歸演算法):
#define P 13 /* P可以改為其他正整數 */
main()
{int a[P],r,c;
for(r=0;r<=P;r++)
{a[r]=1;
for(c=r-1;c>=1;a[c--]+=a[c-1]);
printf("%*d",(P-r)*3+1,a[0]);
for(c=1;c<=r;printf("%6d",a[c++]));
printf("\n");}
}
執行結果:
(應該排列成一個三角形,是貼吧造成現在這個樣子的,不是程序有問題)
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
1 10 45 120 210 252 210 120 45 10 1
1 11 55 165 330 462 462 330 165 55 11 1
1 12 66 220 495 792 924 792 495 220 66 12 1
1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 1
9.源程序(遞歸演算法):
#include "stdio.h"
void printOCT(unsigned long n)
{unsigned long i;
if(i=n>>3)printOCT(i);
putchar((n&7)+48);}
main()
{unsigned long i;
scanf("%ld",&i);
printOCT(i);}
執行結果:
1234567890
11145401322
本題也可以不用遞歸演算法,源程序請參考第7章第三題4。

12 回復:【C語言】《C語言程序設計教程(第二版)》習題答案
但是不同時間印刷的版本課後題不太一樣呢,象我們的是1999年12月第2版,2005年12月第69次印刷的。沒有選擇填空,應用題和樓主不知道有多少相同的,因為看不到原題。這個比較麻煩呢。

作者:210.77.204.* 2006-5-9 18:38 回復此發言

--------------------------------------------------------------------------------

13 回復:【C語言】《C語言程序設計教程(第二版)》習題答案
你對照一下主編和出版社,看看對嗎?(見說明的第一條。)
我不是說叫你有問題另發帖子嗎?

14 第9章 指 針
一、單項選擇題(第276頁)
1-5.DCDAC 6-10.CCABC 11-16.AABBB 16-20.DCDBD

二、填空題(第278頁)
1.①int * ②*z
2.*p++
3.①'\0' ②++
4.①q=p+1 ②q<p+10 ③*q>max ④*q<min

三、編程題(第280頁)
7.源程序:
main()
{int i=0;char c[20];
do{scanf("%s",&c);i++;}
while(strcmp(c,"stop"));
printf("%d\n",i);}
執行結果:
This car ran form Nanyang
to Luoyang without a stop
10
9.源程序:
main()
{char s[255],c[255]={0};int i;
gets(s);
for(i=0;s[i];c[s[i++]]++);
for(i=0;i<255;i++)
if(c[i])printf("%c=%d\t",i,c[i]);}
執行結果:
abcedabcdcd
a=2 b=2 c=3 d=3 e=1

F. C語言程序設計試題 求標准答案 都是多選

1、答案:A
(單引號括起來的都是字元,而且一對單引號最多對應一個字元,\反斜杠是轉義字元的開始,\72是ASCII碼對應的字母H。也就是把H這個字母存到了變數char a中。就一個字元H。)
2、ACDE
解析:
int a=3,b=4,c=5;,
A、a>b
B、a<=b
C、(a||b)>c
D、a<=(b||c)
E、!((a<b)&&!c||b)
優先順序由大到小:() ! && ||
A選項,3>4錯誤,邏輯值0。
B選項,3<=4正確,邏輯值1。
C選項,(3||4)>5,(3||4)"或"邏輯運算符兩邊只要有一個非0的整個值就是1,1>5錯,邏輯值0。
D選項,3<=(4||5)錯誤,邏輯值0。
E選項,!((3<4)&&!5||4),先(3<4)邏輯值1,!5邏輯值0,1&&0是0,0||4是1,!1是0,所以邏輯值0。
3、AC。
解析:A可以,B答案b不能被賦值(自左向右,計算||左側就已經是1了右邊就不用再計算了整個表達式無論右邊如何整個邏輯值必定是1,計算機也就不會計算右邊了)C可以(因為&&兩邊都必須計算才能得出最後的邏輯值答案),D不可以a不能被賦值(&&左邊就一個a,構不成賦值,可能存放一個隨機值,右邊可以被賦值)。
4、ABCD。
外部函數幾乎可以被所有函數調用。只要開頭#include」 "引入。

G. 跪求《C語言程序設計》課本習題答案!!!

習題1參考答案
一、選擇題 1. A 2. D
二、填空題
1. BASIC、FORTRAN、AL_GOL60和COBOL 2. 8
3. 關鍵字
4. 編輯、編譯、鏈接和運行
三、簡答題 1.答:
(1)C語言具有結構化的控制語句。C語言提供了結構化程序所必需的基本控制語句,實現了對邏輯流的有效控制。
(2)C語言具有豐富的數據結構類型。C語言除提供整型、實型、字元型等基本數據類型外,還提供了用基本數據類型構造出的各種復雜的數據結構,如數組、結構、聯合等。C語言還提供了與地址密切相關的指針類型。此外,用戶還可以根據需要自定義數據類型。 (3)C語言具有豐富的運算符。C語言提供了多達34種運算符,豐富的數據類型與豐富的運算符相結合,使C語言的表達力更具靈活性,同時也提高了執行效率。
(4)C語言簡潔、緊湊,使用方便、靈活,程序書寫自由,有9種控制語句。
(5)C語言既具有高級語言的功能,又具有低級語言的許多功能,通常被稱為中級計算機語言。它既是成功的系統描述語言,又是通用的程序設計語言。 (6)C語言與匯編語言相比,可移植性好。
(7)功能強大。C語言具有低級語言的一些功能,所以,生成目標代碼質量高,程序執行效率高。現在許多系統軟體都用C語言來描述,可以大大提高了編程效率。
2.答:運行一個C語言程序,一般需要經過如下幾個步驟:①上機輸入並編輯源程序;②編譯源程序;③與庫函數連接;④生成可執行目標程序;⑤運行目標程序。 3.答:
(1)操作系統的設計與實現。C語言是一種應用非常廣泛的結構化高級程序設計語言,既適合編寫應用軟體,又適合編寫系統軟體。

H. 求c語言程序設計答案

#include
<fstream>
#include
<string.h>
#include
<iostream>
#include
<conio.h>//用getch();
using
namespace
std;
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌Student類﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
class
Student
{
public:
char
name[20];
char
Class[20];
char
Id[20];
int
Cnum;
//C課程得分
int
Mnum;
//數學課程得分
int
Enum;
//英語課程得分
int
Gnum;
//體育
int
sum;
//總分
int
ave;
//平均分
Student
*
Next;
void
Input()
{
cout<<"\t\t請輸入學生的姓名:";
cin>>name;
cout<<"\t\t請輸入學生的班級:";
cin>>Class;
cout<<"\t\t請輸入學生的學號:";
cin>>Id;
cout<<"\t\t請輸入C++的成績:";
cin>>Cnum;
cout<<"\t\t請輸入數學課程的成績:";
cin>>Mnum;
cout<<"\t\t請輸入英語課程的成績:";
cin>>Enum;
cout<<"\t\t請輸入日語的成績:";
cin>>Gnum;
sum=Cnum+Mnum+Enum+Gnum;
ave=(Cnum+Mnum+Enum+Gnum)/4;
}
void
ReadFile(istream
&
in)
{
in>>name>>Class>>Id>>Cnum>>Mnum>>Enum>>Gnum>>ave>>sum;
}
void
Show()
{
cout<<"姓名:"<<name<<endl<<"班級:"<<Class<<endl<<"學號:"<<Id<<endl<<"C++:"<<Cnum<<endl
<<"數學:"<<Mnum<<endl<<"外語:"<<Enum<<endl<<"日語:"<<Gnum<<endl<<"平均成績:"<<ave<<endl<<"總成績:"<<sum<<endl<<endl<<endl;
}
};
//﹌﹌﹌﹌﹌﹌﹌﹌﹌Studentmassage類﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
class
Studentmassage
{
public:
Studentmassage();
~Studentmassage();
void
ShowMenu();
void
Find();
void
Save();
void
ModifyItem();
void
RemoveItem();
void
Swap(Student
*,Student
*);
void
Sort();
int
ListCount();
void
Display()
{
for(Student
*
p=Head->Next;p!=End;p=p->Next)
p->Show();
cout<<"輸入任意字元!繼續……";
getch();
}
void
AddItem()
{
End->Input();
End->Next=new
Student;
End=End->Next;
cout<<"添加成功!"<<endl;
cout<<"輸入任意字元!繼續……";
getch();
}
private:
Student
*
Head,*
End;
ifstream
in;
ofstream
out;
Student
*FindItem(char
*
name)
{
for(Student
*
p=Head;p->Next!=End;p=p->Next)
if(!strcmp(p->Next->name,name))return
p;
return
NULL;
}
Student
*FindID(char
*
Id)
{
for(Student
*
p=Head;p->Next!=End;p=p->Next)
if(!strcmp(p->Next->Id,Id))return
p;
return
NULL;
}
Student
*FindCLASS(char
*
Class)
{
for(Student
*
p=Head;p->Next!=End;p=p->Next)
if(!strcmp(p->Next->Class,Class))return
p;
return
NULL;
}
}Grade;
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌構造函數﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
Studentmassage::Studentmassage()
{
Head=new
Student;
Head->Next=new
Student;
End=Head->Next;
in.open("sort.txt");
if(!in)
cout<<"這是一個新系統,無學生信息。請先輸入。"<<endl;
else
{
while(!in.eof())
{
End->ReadFile(in);
if(End->name[0]=='\0')break;
End->Next=new
Student;
End=End->Next;
}
in.close();
cout<<"\t\t讀取學生信息成功!"<<endl;
}
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌析構函數﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
Studentmassage::~Studentmassage()
{
Save();
for(Student
*
temp;Head->Next!=End;)
{
temp=Head->Next;
Head->Next=Head->Next->Next;
delete
temp;
}
delete
Head,End;
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌菜單﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void
Studentmassage::ShowMenu()
{
cout<<"〓〓〓〓〓〓〓〓〓〓










〓〓〓〓〓〓〓〓〓〓"<<endl;
cout<<"〓〓〓〓〓〓〓★★★★★
★★★★★★★
★★★★★〓〓〓〓〓〓〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★

1.增加學生成績

★〓〓〓〓〓〓〓〓〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★

2.顯示學生成績

★〓〓〓〓〓〓〓〓〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★

3.排序統計成績

★〓〓〓〓〓〓〓〓〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★

4.查找學生成績

★〓〓〓〓〓〓〓〓〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★

5.刪除學生成績

★〓〓〓〓〓〓〓〓〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★

6.修改學生信息

★〓〓〓〓〓〓〓〓〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★

0.安全退出系統

★〓〓〓〓〓〓〓〓〓"<<endl;
cout<<"\n\t\t\n\t\t請選擇:";
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌查找函數﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void
Studentmassage::Find()
{
char
name[20]
,Id[10],Class[20];
int
x;
Student
*
p=NULL;
cout<<"\n\t\t*********************************\n";
cout<<"\t\t※
1.按學生的姓名查找\n\t\t※
2.按學生學號查找\n\t\t※
3.按學生班級查找";
cout<<"\n\t\t*********************************\n請選擇:";
cin>>x;
switch(x)
{
case
1:{cout<<"\t\t請輸入要查找的學生的姓名:";cin>>name;
if(p=FindItem(name))
{
p->Next->Show();
cout<<"輸入任意字元!繼續……";
getch();
}
else
{
cout<<"\t\t沒有找到該姓名的學生!"<<'\n'<<endl;
cout<<"輸入任意字元!繼續……";
getch();
}
}break;
case
2:
{
cout<<"\t\t請輸入要查找的學生的學號:";cin>>Id;
if(p=FindID(Id))
{
p->Next->Show();
cout<<"輸入任意字元!繼續……";
getch();
}
else
{
cout<<"\t\t沒有找到該學號的學生!"<<'\n'<<endl;
cout<<"輸入任意字元!繼續……";
getch();
}
}break;
case
3:{cout<<"\t\t請輸入要查找的學生的班級:";cin>>Class;
if(p=FindCLASS(Class))
{
p->Next->Show();
cout<<"輸入任意字元!繼續……";
getch();
}
else
{
cout<<"\t\t沒有找到該班級的學生!"<<'\n'<<endl;
cout<<"輸入任意字元!繼續……";
getch();
}
}break;
}
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌修改信息﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void
Studentmassage::ModifyItem()
//修改信息
{
char
ID[20];
Student
*
p=NULL;
cout<<"\t\t請輸入要修改的人的學號:";cin>>ID;
if(p=FindID(ID))
{
cout<<"\t\t已找到學生的信息,請輸入新的信息!"<<endl;
p->Next->Input();
cout<<"修改成功!"<<endl;
cout<<"輸入任意字元!繼續……";
getch();
}
else
{
cout<<"\t\t沒有找到!"<<endl;
cout<<"輸入任意字元!繼續……";
getch();
}
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌刪除信息﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void
Studentmassage::RemoveItem()
//
刪除信息
{
char
ID[20];
Student
*
p=NULL,*temp=NULL;
cout<<"\t\t請輸入要刪除的學生的學號:";cin>>ID;
if(p=FindID(ID))
{
temp=p->Next;
p->Next=p->Next->Next;
delete
temp;
cout<<"\t\t刪除成功!"<<endl;
cout<<"輸入任意字元!繼續……";
getch();
}
else
{
cout<<"\t\t沒有找到!"<<endl;
cout<<"輸入任意字元!繼續……";
getch();
}
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void
Studentmassage::Swap(Student
*p1,
Student
*p2)
{
Student
*temp=new
Student;
strcpy(temp->name,p1->name);
strcpy(temp->Id,p1->Id);
temp->Cnum=p1->Cnum;
temp->Mnum=p1->Mnum;
temp->Enum=p1->Enum;
temp->sum=p1->sum;
strcpy(p1->name,p2->name);
strcpy(p1->Id,p2->Id);
p1->Cnum=p2->Cnum;
p1->Mnum=p2->Mnum;
p1->Enum=p2->Enum;
p1->sum=p2->sum;
strcpy(p2->name,temp->name);
strcpy(p2->Id,temp->Id);
p2->Cnum=temp->Cnum;
p2->Mnum=temp->Mnum;
p2->Enum=temp->Enum;
p2->sum=temp->sum;
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
int
Studentmassage::ListCount()//統計當前的記錄總數
{
if(!
Head)
return
0;
int
n=0;
for(Student
*
p=Head->Next;p!=End;p=p->Next)
{
n++;
}
return
n;
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void
Studentmassage::Sort()//對當前學生進行排序
{
cout
<<"Sorting..."<<endl;
Student
*p=NULL,*p1=NULL,*k=NULL;
int
n=Studentmassage::ListCount();
if(n<2)
return;
for(p=Head->Next;p!=End;p=p->Next)
for(k=p->Next;k!=End;k=k->Next)
{
if(p->sum>k->sum)
{
Studentmassage::Swap(p,k);
}
}
cout
<<"排序完成!"<<endl;
getch();
return;
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌保存函數﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void
Studentmassage::Save()
{
out.open("sort.txt");
for(Student
*p=Head->Next;p!=End;p=p->Next)
out<<p->name<<"\t"<<p->Class<<"\t"<<p->Id<<"\t"
<<p->Cnum<<"\t"<<p->Mnum<<"\t"<<p->Enum<<"\t"<<p->Gnum<<"\t"<<p->ave<<"\t"<<p->sum<<'\n';
out.close();
}
void
code()
//密碼
{
char
s1[20]="123",s2[20];
cout<<"請輸入密碼:";
while(cin>>s2)
{
if(!strcmp(s1,s2))
{
Grade.ModifyItem();break;
}
else
cout<<"你輸入的密碼不正確,請重新輸入:";
}
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌主函數﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
int
main()
{
int
x,i=0;
bool
quit=false;
cout<<"\t\t§§§§§§§§§§§§§§§§§§§§§§§§§§"<<endl;
for(i=0;i<3;i++)
cout<<"\t\t◎\t\t\t\t\t\t
◎"<<endl;
cout<<"\t\t◎★★★★【
歡迎進入學生成績管理系統
】★★★★◎"<<endl;
for(i=0;i<3;i++)
cout<<"\t\t◎\t\t\t\t\t\t
◎"<<endl;
cout<<"\t\t§§§§§§§§§§§§§§§§§§§§§§§§§§\n"<<endl;;
cout<<"請按任意鍵開始……";
getch();
while(!quit)
{
system("cls");
Grade.ShowMenu();
cin>>x;
switch(x)
{
case
0:cout<<"★★★★感謝您的使用★★★★"<<endl;quit=true;break;
case
1:Grade.AddItem();break;
case
2:Grade.Display();break;
case
3:Grade.Sort();break;
case
4:Grade.Find();break;
case
5:Grade.RemoveItem();break;
case
6:code();break;
}
}
return
0;
}
我稍微改了下,應該可以用~
額~~你們一定要C編嗎~C++不可以嘛?