当前位置:首页 » 招生排名 » 南昌大学c语言程序设计第六章循环控制答案

南昌大学c语言程序设计第六章循环控制答案

发布时间: 2021-02-10 18:22:25

A. 南昌大学c语言期末考试有题库吗

没有题库的, 不过每年都是类似的题目,考察的知识点都一样.

B. 谭浩强著C语言第二版清华大学出版社第六章习题答案

||第五章 循环控制
5.1
main()
{int a,b,num1,num2,temp;
scanf("%d,%d",&num1,&num2);
if(num1<num2){temp=num1;num1=num2;num2=temp;}
a=num1;b=num2;
while(b!=0)
{temp=a%b;
a=b;
b=temp;}
printf("%d\n",a);
printf("%d\n",num1*num2/a);
}
5.2
#include"stdio.h"
main()
{char c;
int letters=0,space=0,digit=0,other=0;
while((c=getchar())!='\n')
{if(c>='a'&&c<='z'||c>='A'&&c<='Z') letters++;
else if(c==' ')space++;
else if(c>='0'&&c<='9')digit++;
else other++;
}
printf("letters=%d\nspace=%d\ndigit=%d\nother=%d\n",letters,space,digit,other);
}
5.3
main()
{int a,n,count=1,sn=0,tn=0; scanf("%d,%d",&a,&n);
while(count<=n)
{tn+=a;
sn+=tn;
a*=10;
++count;
}
printf("a+aa+aaa+...=%d\n",sn);
}
5.4
main()
{float n,s=0,t=1;
for(n=1;n<=20;n++)
{t*=n;
s+=t;
}
printf("s=%e\n",s);
}
5.5
main()
{int N1=100,N2=50,N3=10;
float k;
float s1=0,s2=0,s3=0;
for(k=1;k<=N1;k++)s1+=k;
for(k=1;k<=N2;k++)s2+=k*k;
for(k=1;k<=N3;k++)s3+=1/k;
printf("s=%8.2f\n",s1+s2+s3);
}
5.6
main()
{int i,j,k,n;
for(n=100;n<1000;n++)
{i=n/100;
j=n/10-i*10;
k=n%10;
if(i*100+j*10+k==i*i*i+j*j*j+k*k*k)
printf("n=%d\n",n);
}
}
5.7
#define M 1000
main()
{int k0,k1,k2,k3,k4,k5,k6,k7,k8,k9;
int i,j,n,s; for(j=2;j<=M;j++)
{n=0;
s=j;
for(i=1;i<j;i++)
{if((j%i)==0)
{n++;
s=s-i;
switch(n)
{case 1:k0=i;break;
case 2:k1=i;break;
case 3:k2=i;break;
case 4:k3=i;break;
case 5:k4=i;break;
case 6:k5=i;break;
case 7:k6=i;break;
case 8:k7=i;break;
case 9:k8=i;break;
case 10:k9=i;break;
}
}
}
if(s==0)
{printf("j=%d\n",j);
if(n>1)printf("%d,%d",k0,k1);
if(n>2)printf(",%d",k2);
if(n>3)printf(",%d",k3);
if(n>4)printf(",%d",k4);
if(n>5)printf(",%d",k5);
if(n>6)printf(",%d",k6);
if(n>7)printf(",%d",k7);
if(n>8)printf(",%d",k8);
if(n>9)printf(",%d\n",k9);
}
}
}
main()
{static int k[10];
int i,j,n,s;
for(j=2;j<=1000;j++)
{n=-1;
s=j;
for(i=1;i<j;i++)
{if((j%i)==0)
{n++; s=s-i;
k[n]=i;
}
}
if(s==0)
{printf("j=%d\n",j);
for(i=0;i<n;i++)
printf("%d,",k);
printf("%d\n",k[n]);
}
}
}
5.8
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.6f\n",s);
}
5.9
main()
{float sn=100.0,hn=sn/2;
int n;
for(n=2;n<=10;n++)
{sn=sn+2*hn;
hn=hn/2;
}
printf("sn=%f\n",sn);
printf("hn=%f\n",hn);
}
5.10
main()
{int day,x1,x2;
day=9;
x2=1;
while(day>0)
{x1=(x2+1)*2;
x2=x1;
day--;
}
printf("x1=%d\n",x1); }
5.11
#include"math.h"
main()
{float a,xn0,xn1;
scanf("%f",&a);
xn0=a/2;
xn1=(xn0+a/xn0)/2;
do
{xn0=xn1;
xn1=(xn0+a/xn0)/2;
}
while(fabs(xn0-xn1)>=1e-5);
printf("a=%5.2f\n,xn1=%8.2f\n",a,xn1);
}
5.12
#include"math.h"
main()
{float x,x0,f,f1;
x=1.5;
do
{x0=x;
f=((2*x0-4)*x0+3)*x0-6;
f1=(6*x0-8)*x0+3;
x=x0-f/f1;
}
while(fabs(x-x0)>=1e-5);
printf("x=%6.2f\n",x);
}
5.13
#include"math.h"
main()
{float x0,x1,x2,fx0,fx1,fx2;
do
{scanf("%f,%f",&x1,&x2);
fx1=x1*((2*x1-4)*x1+3)-6;
fx2=x2*((2*x2-4)*x2+3)-6;
}
while(fx1*fx2>0);
do
{x0=(x1+x2)/2;
fx0=x0*((2*x0-4)*x0+3)-6;
if((fx0*fx1)<0)
{x2=x0; fx2=fx0;
}
else
{x1=x0;
fx1=fx0;
}
}
while(fabs(fx0)>=1e-5);
printf("x0=%6.2f\n",x0);
}
5.14
main()
{int i,j,k;
for(i=0;i<=3;i++)
{for(j=0;j<=2-i;j++)
printf(" ");
for(k=0;k<=2*i;k++)
printf("*");
printf("\n");
}
for(i=0;i<=2;i++)
{for(j=0;j<=i;j++)
printf(" ");
for(k=0;k<=4-2*i;k++)
printf("*");
printf("\n");
}
}
5.15
main()
{char i,j,k;
for(i='x';i<='z';i++)
for(j='x';j<='z';j++)
{if(i!=j)
for(k='x';k<='z';k++)
{if(i!=k&&j!=k)
{if(i!='x'&&k!='x'&&k!='z')
printf("\na--%c\tb--%c\tc--%c\n",i,j,k);
}
}
}
}
第六章 数组
6.1 #include <stdio.h>
#include <math.h>
#define N 101
void main()
{ int i,j,line,a[N];
for (i=2;i<N;i++) a[i]=i;
for (i=2;i<sqrt((double)N);i++)
for (j=i+1;j<N;j++)
{if(a[i]!=0 && a[j]!=0)
if (a[j]%a[i]==0)
a[j]=0; }
printf("\n");
for (i=2,line=0;i<N;i++)
{ if(a[i]!=0)
{ printf("%5d ",a[i]);
line++; }
if(line==10)
{ printf("\n");
line=0; }
}
}
6.2
#define N 10
main()
{int i,j,min,temp,a[N];
for(i=0;i<N;i++)
scanf("%d",&a);
for(i=0;i<N-1;i++)
{min=i;
for(j=i+1;j<N;j++)
if(a[min]>a[j])min=j;
temp=a;
a=a[min];
a[min]=temp;
}
for(i=0;i<N;i++)
printf("%5d",a);
}

6.3
main()
{float a[3][3],sum;
int i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++) {scanf("%f",&sum);
a[j]=sum;
}
for(i=0;i<3;i++)
sum=sum+a;
printf("sum=%f",sum);
}
6.4
main()
{int a[11]={1,4,6,9,13,16,19,28,40,100};
int temp1,temp2,number, end,i,j;
scanf("%d",&number);
end=a[9];
if(number>end) a[10]=number;
else
{for(i=0;i<10;i++)
{if(a>number)
{temp1=a;
a=number;
for(j=i+1;j<11;j++)
{temp2=a[j];
a[j]=temp1;
temp1=temp2;
}
break;
}
}
}
for(i=0;i<11;i++)
printf("%6d",a);
}
6.5
#define N 5
main()
{int a[N]={8,6,5,4,1},i,temp;
for(i=0;i<N/2;i++)
{temp=a;
a=a[N-i-1];
a[N-i-1]=temp;
}
for(i=0;i<N;i++)
printf("%4d",a);
}
6.6 #define N 11
void main()
{int i,j,a[N][N]={0};
for(i=1;i<N;i++)
{a[i][1]=1;
a[i][i]=1;
}
for(i=3;i<N;i++)
for(j=2;j<i;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j];
for(i=1;i<N;i++)
{for(j=1;j<=i;j++)
printf("%6d",a[i][j]);
printf("\n");
}
}
6.7
main()
{int a[16][16],i,j,k,p,m,n;
p=1;
while(p==1)
{scanf("%d",&n);
if((n!=0)&&(n<=15)&&(n%2!=0))p=0;
}
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
a[j]=0;
j=n/2+1;
a[1][j]=1;
for(k=2;k<=n*n;k++)
{i=i-1;
j=j+1;
if((i<1)&&(j>n))
{i=i+2;
j=j-1;
}
else
{if(i<1)i=n;
if(j>n)j=1;
}
if(a[j]==0)a[j]=k;
else
{i=i+2;
j=j-1; a[j]=k;
}
}
for(i=1;i<=n;i++)
{for(j=1;j<=n;j++)
printf("%3d",a[j]);
printf("\n");
}
}
6.8
#define N 10
#define M 10
main()
{int i,j,k,m,n,flag1,flag2,a[N][M],max,maxi,maxj;
scanf("%d,%d",&n,&m);
for(i=0;i<n;i++)
for(j=0;j<m;j++)
scanf("%d",&a[j]);
flag2=0;
for(i=0;i<n;i++)
{max=a[0];
for(j=0;j<m;j++)
if(max<a[j])
{max=a[j];
maxj=j;
}
for(k=0,flag1=1;k<n&&flag1;k++)
if(max>a[k][maxj])flag1=0;
if(flag1)
{ printf("\na[%d][%d]=%d\n",i,maxj,max);
flag2=1;
}
}
if(!flag2) printf("NOT");
}
6.9
#include<stdio.h>
#define N 15
main()
{int i,j,number,top,bott,min,loca,a[N],flag;
char c;
for(i=0;i<=N;i++)
scanf("%d",&a);
flag=1; while(flag)
{scanf("%d",&number);
loca=0;
top=0;
bott=N-1;
if((number<a[0])||(number>a[N-1]))
loca=-1;
while((loca==0)&&(top<=bott))
{min=(bott+top)/2;
if(number==a[min])
{loca=min;
printf("number=%d,loca=%d\n",number,loca+1);
}
else if(number<a[min])
bott=min-1;
else
top=min+1;
}
if(loca==0||loca==-1)
printf("%d not in table\n",number);
printf("continue Y/N or y/n\n");
c=getchar();
if(c=='N'||c=='n')flag=0;
}
}
6.10
main()
{int i,j,uppn,lown,dign,span,othn;
char text[3][80];
uppn=lown=dign=span=othn=0;
for(i=0;i<3;i++)
{gets(text);
for(j=0;j<80&&text[j]!='\0';j++)
{if(text[j]>='A'&&text[j]<='Z')
uppn++;
else if(text[j]>='a'&&text[j]<='z')
lown++;
else if(text[j]>='0'&&text[j]<='9')
dign++;
else if(text[j]==' ')
span++;
else
othn++;
} }
for(i=0;i<3;i++)
printf("%s\n",text);
printf("uppn=%d\n",uppn);
printf("lown=%d\n",lown);
printf("dign=%d\n",dign);
printf("span=%d\n",span);
printf("othn=%d\n",othn);
}
6.11
main()
{static char a[5]={'*','*','*','*','*'};
int i,j,k;
char space=' ';
for(i=0;i<=5;i++)
{printf("\n");
for(j=1;j<=3*i;j++)
printf("%1c",space);
for(k=0;k<=5;k++)
printf("%3c",a[k]);
}
}
6.12
#include<stdio.h>
main()
{int i,n;
char ch[80],tran[80];
gets(ch);
i=0;
while(ch!='\0')
{if((ch>='A')&&(ch<='Z'))
tran=26+64-ch+1+64;
else if((ch>='a')&&(ch<='z'))
tran=26+96-ch+1+96;
else
tran=ch;
i++;
}
n=i;
for(i=0;i<n;i++)
putchar(tran);
}
6.13
main() {char s1[80],s2[40];
int i=0,j=0;
scanf("%s",s1);
scanf("%s",s2);
while(s1!='\0')i++;
while(s2[j]!='\0')s1[i++]=s2[j++];
s1='\0';
printf("s=%s\n",s1);
}
6.14
#include<stdio.h>
main()
{int i,resu;
char s1[100],s2[100];
gets(s1);
gets(s2);
i=0;
while((s1==s2)&&(s1!='\0'))i++;
if(s1=='\0'&&s2=='\0')resu=0;
else
resu=s1-s2;
printf("s1=%s,s2=%s,resu=%d\n",s1,s2,resu);
}
6.15
#include"stdio.h"
main()
{char from[80],to[80];;
int i;
scanf("%s",from);
for(i=0;i<=strlen(from);i++)
to=from;
printf("%s\n",to);
}

C. 求C语言程序设计实例教程课后习题答案,人民邮电出版社,主编管银枝,胡银辉

答案没有,不过我有视频,不知道你需要不,因为我是自学,我现在专就在看,感觉还不属错。一听就能听懂的那种,感觉比较适合我这样入门刚学的人。最吸引的地方就是讲的难理解的概念讲的特别好,用形象比喻举例讲概念,比如变量比喻成装东西的盒子,我一下子就理解了变量赋值为什么是从右往左。还有很多这样类似的比喻。比我之前看的什么郝斌曾怡金文的晦涩难懂的都好多了。

D. c语言 谭浩强的《c程序设计》第六章,6.9节程序距离的例6.10

它是让你在循环的时候把字符输入输入流里面,getchar()的确是只能就收一个字符,但是如回果你没有按下回答车键,就不会把输入流里面的内容送入内存,当且仅当你回车时,程序才强制将输入流的内容送入内存,系统内存就会从输入流逐个读字符并输出一个个字符。

E. 这是我们的课堂作业,是C语言程序设计第六章 函数 方面的题目,有谁会解的请解一下吧,十分感谢了!!!

这个其实也没什么好去分析的,按照题目的要求去做就可以了。
比如说这个题目,题干已经很明确的告诉你要去你写一个函数完成两个字符串的连接(不使用库函数strcat),即把p2所指的字符串连接到p1所指的字符串后。

那么你按要求写就好了
给个例子
void fun(char p1[], char p2[])
{
int i=0,j=0;
while(p1[i]!='\0')
{
i++;
}/*因为是p2所指的字符串连接到p1所指的字符串后。所以找到p1字符串的结尾*/
while(p2[j]!='\0')
{
p1[i]=p2[j];
i++;
j++;
}/*从p1字符串结尾开始依次用p2的字符填充直到p2中的内容为'\0'*/

p1[i]='\0';
/*要注意给p1[]字符串结束标志,这个地方很容易忘记。因为当p2[j]是'\0'时已经退出循环了,所以p1[]是没有结束标志的,可能会导致程序崩溃哦。*/
}

2级C是很基础的 考来考去就那么几个上机题 说实话 你那几种题型一样写几个就OK了 呵呵 但是要细心 2级C考的就是你细不细心的问题 加油 祝你考试顺利
I never think of the future. It comes soon enough.

F. c语言教程习题答案

第一章
1.1 EXE
1.2 C OBJ EXE
1.3 顺序 选择 循环

第二章
一. 选择题
2.1 B 2.2 D 2.3 B 2.4 A 2.5 C 2.6 A 2.7 B
2.8 B 2.9 D 2.10 C 2.11 B 2.12 B 2.13 A
二. 填空题
2.14 11 12
2.15 4.2 4.2
2.16 { } 定义 执行语句
2.17 关键字 用户标识符
2.18 int float double
2.19 float a1=1; float a2=1;
2.20 存储单元
2.21 3.5
2.22 (a*b)/c a*b/c a/c*b
2.23 把常量10赋给变量s
2.24 位 1或0
2.25 8 127 0111111 -128 10000000
2.26 32767 -32768 1000000000000000
2.27 10 8 16
三. 上机改错题
2.28
#include "stdio.h"; 删除行尾的";"
main(); / * main function * / 删除")"后的";",注释中的*要紧靠“/”,即应为“/*”和“*/”
函数开始处遗失了一个“{”
float r,s ; /*/*r is radius*/,/* s is area of circuilar*/*/ 注释符号不可嵌套使用
r = 5.0 ;
s = 3.14159 * r * r ;
printf("%f\n",s) 行尾遗失了“;”
函数结束处遗失了一个“}”

2.29
#include "stdio.h"
main /* main function */ main后遗失了“()”
{
float a,b,c,v; /*a,b,c are sides, v is volume of cube */
a=2.0; b=3.0; c=4.0 行尾遗失了“;”
v=a*b*c;
printf("%f\n", v) 行尾遗失了“;”
}

第三章
一. 选择题
3.1 C 3.2 C 3.3 D 3.4 C 3.5 D 3.6 B 3.7 C 3.8 D 3.9 A 3.10 B
3.11 C 3.12 D 3.13 D 3.14 A 3.15 C 3.16 C 3.17 C 3.18 无答案 3.19 C 3.20 B

二. 填空题
3.21 (1)-2002500(2)i=-200,j=2500
(3)i=-200
j=2500
3.22 12 0 0
3.23 一条语句 ;
3.24 ;
3.25 100,25.81,1.89234 100 25.81 1.89234 100 25.81 1.89234
3.26 x=127,x= 127,x= 177,x= 7f,x= 127
3.27 x=127,x=127 ,x=$127 ,x=$000127,x=d
3.28 a=513.789215,a= 513.79,a= 513.78921500,a= 513.78921500

三. 编程题和改错题
3.29 修改后的程序如下:
main()
{
double a,b,c,s,v;
printf("input a,b,c:");
scanf("%lf%lf%lf",&a,&b,&c);
s =a*b;
v=a*b*c;
printf("a=%f,b=%f,c=%f\n", a,b,c);
printf("s=%f,v=%f\n",s,v);
}
3.30
#include
main()
{
int a=560,b=60;
printf("560 minute is %d hour and %d minute.\n",a/b,a%b);
}
3.31
#include
main()
{
int a,b;
a=1500;b=350;
printf("a div b is : %d\n",a/b);
printf("a mod b is : %d\n",a%b);
}
3.32
#include
main()
{
double a,b,c,ave;
printf ("input 3 double number : \n");
scanf ("%lf%lf%lf",&a,&b,&c);
printf ("%.1f\n",(a b c)/3);
}
3.33
#include
void main()
{
int a,b,c,t;
printf("请依次输入整数a,b,c:");
scanf("%d%d%d",&a,&b,&c);
printf("\n你输入的值是: a=%d,b=%d,c=%d\n",a,b,c);
t=b;b=a;a=c;c=t;
printf("交换之后的值是:a=%d,b=%d,c=%d\n",a,b,c);
}

第四章
一. 选择题
4.1 A 4.2 A 4.3 A 4.4 D 4.5 C 4.6 A 4.7 B 4.8 C 4.9 D 4.10 C
二. 填空题
4.11 非0 0
4.12 < > >= <=同级 == !=同级
4.13 ! && ||
4.15 !
4.16 a == b || a < c x > 4 || x < -4
4.17 1
4.18 x <= 0 1 > 0
4.19 3 2 2
4.20 *#

三. 编程题
4.21 略
4.22
#include

/* 检查日期的合法性 */
int checkdate(int year, int month, int day)
{
if(year < 1900 || year > 2005)
{
printf("输入的年份无效!\n");
return 0;
}
else if(month < 0 && month > 12)
{
printf("输入的月份无效!\n");
return 0;
}
else if(day <= 0 && day > 31)
{
printf("输入的日期无效!\n");
return 0;
}
else
{
switch(month)
{
case 4:
case 6:
case 9:
case 11:
if(day > 30)
{
printf("输入的日期无效!\n");
return 0;
}
break;
case 2:
if((year%4 == 0 && year0 != 0) || year@0 == 0)
{
if(day > 29)
{
printf("输入的日期无效!\n");
return 0;
}
}
else
{
if(day > 28)
{
printf("输入的出生日期无效!\n");
return 0;
}
}
break;
}/* end of switch(m0)*/
}
return 1;
}

void main()
{
int y0, m0, d0; /* 生日 */
int y1, m1, d1; /* 当前日期 */
int years, months, days; /* 实足年龄*/

printf("请输入学生的生日:");
scanf("%d%d%d", &y0,&m0,&d0);

if(checkdate(y0, m0, d0))
{
printf("请输入当前日期:");
scanf("%d%d%d", &y1,&m1,&d1);
/*当前日期合法性检查*/
if(!checkdate(y1, m1, d1))
{
return;
}
else if(y0 > y1)
{
printf("出生年份比当前年份晚!\n");
return;
}
else if(y0 == y1)
{
if(m0 > m1)
{
printf("出生年月比当前年月晚!\n");
return;
}
else if(m0 == m1)
{
if(d0 > d1)
{
printf("出生年月日比当前年月日晚!\n");
return;
}
}
}
}

/* 计算实足年龄 */
years = y1 - y0;
months = m1 - m0;
days = d1 - d0;

/* 修正实足年龄天数*/
if(days < 0)
{
months--;
switch(m1)
{
case 1:
case 5:
case 7:
case 10:
case 12:
days = 30;
break;
case 2:
case 4:
case 6:
case 8:
case 9:
case 11:
days = 31;
break;
case 3:
if((y1%4 == 0 && y10 != 0) || y1@0 == 0)
{
days = 29;
}
else
{
days = 28;
}
break;
}/* end of switch(m1) */

}/* end of if(days < 0) */

/* 修正实足年龄月数*/
if(months < 0)
{
months = 12;
years--;
}/* end of if(months < 0) */

printf("出生日期: %d年%d月%d日\n", y0, m0, d0);
printf("当前日期: %d年%d月%d日\n", y1, m1, d1);
printf("实足年龄: %d年%d月%d日\n", years, months, days);

return;
}

4.23
#include

void main()
{
int a;
printf ("请输入一个整数 :");
scanf ("%d",&a);
if (a%2==0)
{
printf ("%d 是偶数\n", a);
}
else
{
printf ("%d 是奇数\n", a);
}
}

4.24
#include

void main()
{
int a,b,c,temp,max;
printf ("请输入三个整数 :");
scanf ("%d %d %d",&a,&b,&c);
temp=(a>b)? a:b;
max=(temp>c)? temp:c;
printf ("\n");
printf ("你输入的数中最大的是 %d.\n",max);
}

4.25
(1)不嵌套的if语句
#include

void main()
{
int x,y;
printf("input x :");
scanf("%d",&x);
if ( x>-5 && x<0 )
{
printf("y is %d\n",y=x);
}
if ( x==0 )
{
printf("y is %d\n",y=x-1);
}
if ( x>0 && x<10 )
{
printf("y is %d\n",y=x 1);
}
if ( x>=10 || x<=-5)
{
printf("error\n");
}
}
(2)嵌套的if语句
#include

void main()
{
int x,y;
printf("input x :");
scanf("%d",&x);
printf("\n");
if(x < 0)
{
if(x > -5)
{
printf("y is %d.\n",y=x);
}
else
{
printf("error!\n");
}
}
if(0 == x)
{
printf("y is %d.\n",y=x-1);
}
if(x > 0)
{
if(x < 10)
{
printf("y is %d.\n",y=x 1);
}
else
{
printf("error!\n");
}
}
}
(3)if_else语句
#include

void main()
{
int x,y;
printf("input x :");
scanf("%d",&x);
if( x>-5 && x<0 )
{
printf("y is %d.\n",y=x);
}
else if( x==0 )
{
printf("y is %d.\n",y=x-1);
}
else if( x>0 && x<10 )
{
printf("y is %d.\n",y=x 1);
}
else
{
printf("error!\n");
}
}
(4)switch语句
#include

void main()
{
int x,y;
printf("input x : ");
scanf("%d",&x);
switch (x)
{
case -4:
case -3:
case -2:
case -1:
printf("y is %d.\n",y=x);
break;
case 0:
printf("y is %d.\n",y=x-1);
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
printf("y is %d.\n",y=x 1);
break;
default:
printf("error!\n");
}
}

第五章

一. 选择题
5.1 D 5.2 C 5.3 B 5.4 C 5.5 C 5.6 B 5.7 D 5.8 A 5.9 D 5.10 D

二. 填空题
5.11 5 4 6
5.12 死循环
5.13 -1
5.14 11
5.15 d=1.0 k k<=n
5.16 x>=0 x
三. 编程题
5.17
#include
void main()
{
int i;
int sig = 1;
int sum = 0;
for(i=1; i<=101; i ,i )
{
sum = sig*i;
sig *= -1;
}
printf("sum=%d\n", sum);
}

5.18
(1)
#include

void main()
{
int i;
double m=1.0;
double e = 1.0;
for(i=1; i<50; i )
{
m *= i;
e = 1/m;
}
printf("e=%f\n",e);
}
(2)
#include

void main()
{
int i=1;
double m=1.0;
double e = 1.0;
while(1/m >= 0.0004)
{
m *= i;
e = 1/m;
i ;
}
printf("e=%f\n",e);
}

5.19
#include

void main()
{
int year;
int col = 0;
for(year=1600; year<=2000; year )
{
if((year%4 == 0 && year0 != 0) || year@0 == 0)
{
printf("%d\t", year);
col ;
if(col%5 == 0)
{
printf("\n");
}
}
}
printf("\n");
}

5.20
#include
#define N 7

void main()
{
int i;
int j;
int m;
int k = N/2;
for(i=0; i {
m = i-k;
if(m < 0)
{
m *= -1;
}
for(j=0; j {
printf(" ");
}
for(j=0; j<2*(k-m) 1; j )
{
printf("*");
}
printf("\n");
}
}

第六章

一. 选择题
6.1 B 6.2 D 6.3 A 6.4 A 6.5 B 6.6 D 6.7 D 6.8 B 6.9 A 6.10 A 6.11 C

二. 填空题
6.12 -1
6.13 1
6.14 ctype.h
6.15 1
6.16 10A 20B 30C 40D
6.17 7.29 101.298AB
6.18 A7.29B101.298
6.19 A B C (每个字符后有三个空格)

三. 编程题
6.20
#include
#define N 80

void main()
{
char str[N];
int iLoop = 0;
gets(str);
while(str[iLoop])
{
printf("%c-%d\t", str[iLoop],str[iLoop]);
iLoop ;
if(iLoop%3 == 0)
{
printf("\n");
}
}
printf("\n");
}

6.21
#include
#define N 80

void main()
{
char str[N];
int num = 0;
int iLoop = 0;
gets(str);
while(str[iLoop])
{
if(str[iLoop] >= '0' && str[iLoop] <= '9')
{
num = 10*num (str[iLoop] - '0');
}
iLoop ;
}
printf("%d\n",num);
}

6.22
#include
#include
#define N 80

void main()
{
char str[N];
int num = -1;
do
{
gets(str);
num ;
}while(strcmp(str, "EOF"));
printf("您输入了%d行字符!\n",num);
}

6.23
#include
#define N 80

void main()
{
char str[N];
int iLoop = 0;
int num = 0;
gets(str);
while(str[iLoop] && iLoop < N)
{
if(str[iLoop] >= 'a' && str[iLoop] <= 'z')
{
num ;
}
iLoop ;
}
printf("您输入了字符中有%d个小写字母!\n",num);
}

6.24
#include

void main()
{
int line;
int iLoop1;
int iLoop2;

printf("请输入图案的行数(不大于26):");
scanf("%d", &line);
for(iLoop1 = 0; iLoop1 < line; iLoop1 )
{
for(iLoop2 = 0; iLoop2 < line - iLoop1; iLoop2 )
{
printf(" ");
}
for(iLoop2 = 0; iLoop2 < 2*iLoop1 1; iLoop2 )
{
printf("%c",iLoop1 'A');
}
printf("\n");
}
}
第七章

一. 选择题
7.1 C 7.2 C 7.3 B 7.4 C 7.5 A 7.6 D 7.7 A

二. 填空题
7.8 12
7.9 9.000000
7.10 4
7.11 n=1 s
7.12 <=y z*x
7.13 1 s*i 0 f(k)

三. 程序调试和编程题
7.14
fun(int n)
{ int k,yes;
for(k=2; k<=n/2; k )
{
if(n%k == 0) { yes = 0; break;}
else yes = 1;
}
return yes;
}
7.15
int mymod(int a, int b)
{
return a%b;
}
7.16
double fun(int n)
{
double sum = 0;
int iLoop;
int sig = -1;
for(iLoop=1; iLoop<=n; iLoop )
{
sig *= -1;
sum = sig*1.0/iLoop;
}
return sum;
}
7.17
double fun(int n)
{
double t = 1.0;
int iLoop;
long tmp;
for(iLoop=2; iLoop<=n; iLoop )
{
tmp = iLoop*iLoop;
t -= 1.0/tmp;
}
return t;
}
7.18
#include
#include

double fun(double x)
{
return x*x 5*x 4;
}

void main()
{
int x = 2;
printf("y1=%f\n", fun(x));
printf("y2=%f\n", fun(x 15));
printf("y3=%f\n", fun(sin(x)));
}
2005-7-29 17:53 myhome1702
第八章
一. 选择题
8.1 A 8.2 B 8.3 B 8.4 C 8.5 B 8.6 B 8.7 C 8.8 D 8.9 B 8.10 C 8.11 C 8.12 C

二. 填空题
8.13 110
8.14 7 1
8.15 (1)char *p=&ch; (2) p=&ch; (3)scanf("%c",p); (4)*p='A'; (5)printf("%c",*p);
8.16 (1)s=p 3; (2)s=s-2 (3)50 (4)*(s 1) (5)2 (6)10 20 30 40 50

三. 编程题
8.17
void fun(double x, double y, double *sum, double *div)
{
*sum = x y;
*div = x - y;
return;
}
8.18
void fun(double x, double y, double z, double *max, double *min)
{
*max = x;
*min = x;
if(*max < y)
{
*max = y;
}
if(*max < z)
{
*max = z;
}
if(*min > y)
{
*min = y;
}
if(*min > z)
{
*min = z;
}
return;
}

第九章
一. 选择题
9.1 D 9.2 A 9.3 A 9.4 C 9.5 C 9.6 A 9.7 B 9.8 D 9.9 C 9.10 C
9.11 C 9.12 D 9.13 D 9.14 A 9.15 A 9.16 A 9.17 C 9.18 C

二. 填空题
9.19 9 0
9.20 6
9.21 12
9.22 3
9.23 2721
9.24 -850,2,0
9.25 k=p k
9.26 (c=getchar()) c-'A'

三. 编程题
9.27
#include
#define N 81
int main()
{
int counter[10] = {0};
int iLoop = 0;
char str[N];

gets(str);
while(str[iLoop])
{
if(str[iLoop] >= '0' && str[iLoop] <= '9')
{
counter[str[iLoop] - '0'] ;
}
iLoop ;
}
for(iLoop=0; iLoop < 10; iLoop )
{
printf("%d - %d\n", iLoop, counter[iLoop]);
}
return 0;
}
9.28
void fun(int array[], int arraysize, int start)
{
int iLoop;
if(start < arraysize-1)
{
if(start <=0)
{
start = 1;
}
for(iLoop = start; iLoop < arraysize; iLoop )
{
array[iLoop-1] = array[iLoop];
}
}
for(iLoop = 0; iLoop < arraysize; iLoop )
{
printf("No.%d = %d\n", iLoop, array[iLoop]);
}
}
9.29
int fun(int arry1[], int arry2[], int arrysize)
{
int iLoop;
int counter = 0;
for(iLoop = 0; iLoop < arrysize; iLoop )
{
if(arry1[iLoop] % 2)
{
arry2[counter ] = arry1[iLoop];
}
}
return counter;
}
9.30
void fun(char array[], int arraysize)
{
int iLoop1;
int iLoop2;
char temp;
/* 冒泡排序 */
for(iLoop1 = 0; iLoop1 < arraysize - 1; iLoop1 )
{
for(iLoop2 = 0; iLoop2 < arraysize - 1 - iLoop1; iLoop2 )
{
if(array[iLoop2] < array[iLoop2 1])
{
temp = array[iLoop2];
array[iLoop2] = array[iLoop2 1];
array[iLoop2 1] = temp;
}
}
}
}
9.31
#include

void fun(int array[], int arraysize, int inertNumber)
{
int iLoop;
int iLoop2;
if(array[0] < array[arraysize-1])
{
for(iLoop = 0; iLoop< arraysize; iLoop )
{
if(array[iLoop] > inertNumber)
{
for(iLoop2 = arraysize - 1; iLoop2 >= iLoop; iLoop2--)
{
array[iLoop2 1] = array[iLoop2];
}
array[iLoop] = inertNumber;
break;
}
}
if(iLoop >= arraysize)
{
array[arraysize] = inertNumber;
}
}
else
{
for(iLoop = 0; iLoop< arraysize; iLoop )
{
if(array[iLoop] < inertNumber)
{
for(iLoop2 = arraysize - 1; iLoop2 >= iLoop; iLoop2--)
{
array[iLoop2 1] = array[iLoop2];
}
array[iLoop] = inertNumber;
break;
}
}
if(iLoop >= arraysize)
{
array[arraysize] = inertNumber;
}
}
}

int main()
{
int iLoop;
int a[20] = {7,6,5,3,2,1};
for(iLoop = 0; iLoop < 6; iLoop )
{
printf("%d ", a[iLoop]);
}
printf("\n");
fun(a, 6, 0);
for(iLoop = 0; iLoop < 7; iLoop )
{
printf("%d ", a[iLoop]);
}
printf("\n");
fun(a, 7, 4);
for(iLoop = 0; iLoop < 8; iLoop )
{
printf("%d ", a[iLoop]);
}
printf("\n");
fun(a, 8, 8);
for(iLoop = 0; iLoop < 9; iLoop )
{
printf("%d ", a[iLoop]);
}
printf("\n");
return 0;
}
9.32
int fun(int number, int array[])
{
int iLoop = 0;
int iLoop2;
int binLen;
int midNumber;
int div;
int remain;

midNumber = number;
do
{
div = midNumber/2;
remain = midNumber%2;
midNumber = div;
array[iLoop ] = remain;
}while(midNumber);

binLen = iLoop;

for(iLoop2 = 0, iLoop = binLen - 1; iLoop2 < iLoop; iLoop2 , iLoop--)
{
midNumber = array[iLoop2];
array[iLoop2] = array[iLoop];
array[iLoop] = midNumber;
}
return binLen;
}
9.33
#include
#include
#define N 15

void fun(int array[], int arraysize)
{
int x;
int iLoop;
int iLoop2;

for(iLoop = 0; iLoop < arraysize; iLoop )
{
iLoop2 = 0;
x = rand() ;
do
{
if(x == array[iLoop2] && iLoop > 0)
{
x = rand() ;
iLoop2 = 0;
}
iLoop2 ;
}while(iLoop2 < iLoop);
array[iLoop] = x;
}
}

int main()
{
int a[N];
int iLoop;

fun(a, N);
for(iLoop = 0; iLoop < N; iLoop )
{
printf("%d\n", a[iLoop]);
}
return 0;
}

第十章
一. 选择题
10.1 C 10.2 B 10.3 C 10.4 B 10.5 C 10.6 A 10.7 C 10.8 A 10.9 C 10.10 C

二. 填空题
10.11 GFEDCB
10.12 XYZ
10.13 SO
10.14 10
10.15 Itis
10.16 strlen(str)-1 j--
10.17 3
10.18 goodgood!

三. 编程题
10.19
char* mygets(char *str)
{
int iLoop = 0;
char ch;
while((ch=getchar()) != '\n')
{
str[iLoop ] = ch;
}
str[iLoop] = '\0';
return str;
}
char * myputs(char *str)
{
int iLoop = 0;
while(str[iLoop])
{
putchar(str[iLoop ]);
}
putchar('\n');
return str;
}
10.20
#include
#include

int fun(char *str)
{
int len;
int iLoop1;
int iLoop2;
int result = 1;

len = strlen(str);
for(iLoop1 = 0, iLoop2 = len - 1; iLoop1 < iLoop2; iLoop1 , iLoop2--)
{
if(str[iLoop1] != str[iLoop2])
{
result = 0;
break;
}
}

return result;
}

int main()
{
char a[20] = "ABCDCBA";
char b[20] = "ABCDEBA";

printf("%d\n", fun(a));
printf("%d\n", fun(b));

return 0;
}
10.21
char fun(char *str, int pos)
{
int len;
int iLoop;
char ch;

len = strlen(str);
if(pos > len)
{
return NULL;
}
ch = str[pos];
for(iLoop = pos; iLoop < len - 1; iLoop )
{
str[iLoop] = str[iLoop 1];
}
str[len-1] = '\0';
return ch;
}
2005-7-29 17:54 myhome1702
第十一章
一. 选择题
11.1 D 11.2 B 11.3 A 11.4 C

二. 填空题
11.5 IJKLEFGHABCD
11.6 7
11.7 8
11.8 *(s j) i 1 i
11.9 17
11.10 (*fun)() (*fun)(a i*h)/h mypoly

三. 编程题
11.11
#include
#include
#define N 81
int main(int argc, char **argv)
{
char sig;
int dig;
int pos;
char str[N] = {'\0'};
char outStr[N] = {'\0'};

if(argc < 2)
{
sig = '-';
dig = 10;
}
else
{
sig = argv[1][0];
dig = argv[1][1] - '0';
}

printf("请输入一个字符串:");
gets(str);

if(sig == '-')
{
pos = strlen(str) - dig;
if(pos <= 0)
{
pos = 0;
}
strcpy(outStr, str pos);
}
else if(sig == ' ')
{
strcpy(outStr, str);
pos = strlen(outStr);
if(pos > dig)
{
pos = dig;
}
outStr[pos] = '\0';
}

printf("处理后的字串为:");
printf("%s\n", outStr);

return 0;
}
11.12
#include
#include

void movebin(char *bin)
{
int len;
int iLoop;
len = strlen(bin);
for(iLoop = len; iLoop > 0; iLoop--)
{
bin[iLoop] = bin[iLoop - 1];
}
return;
}

void fun(int n, char *bin)
{
int pos;
pos = strlen(bin);
if(n == 0)
{
return;
}
if(n == 1)
{
movebin(bin);
bin[0] = '1';
return;
}
movebin(bin);
bin[0] = (n%2) '0';
n /= 2;
fun(n, bin);
return;
}

int main()
{
int a = 4;
char bin[50] = {""};

fun(a, bin);
printf("%s\n", bin);

return 0;
}
11.13
#include

long fun(int n)
{
if(n == 1)
{
return n;
}
else
{
return fun(n-1) n;
}
}

int main()
{
int num;
int sum;

printf("请输入一个自然数:");
scanf("%d", &num);
sum = fun(num);

printf("结果是:%d\n", sum);

return 0;
}
11.14
#include

int fun(int n)
{
if(n == 0 || n == 1)
{
return 1;
}
else
{
return fun(n-1) fun(n-2);
}
}

int main()
{
int num;
int result;

printf("请输入一个自然数:");
scanf("%d", &num);

result = fun(num);
printf("斐波拉契级数为:%d\n", result);

return 0;
}

第十二章
一. 选择题
12.1 B 12.2 B 12.3 A 12.4 C 12.5 D 12.6 B 12.7 A 12.8 A

二. 填空题
12.9 2,5,1,2,3,-2
12.10 2468

第十三章
一. 选择题
13.1 A 13.2 C 13.3 B 13.4 C 13.5 D 13.6 D 13.7 D

二. 填空题
13.8 ar=9 ar=9 ar=11
13.9 int* s *b

三. 编程题
13.10
#define MYALPHA(C) ((C>='A' && C<='Z') || (C>='a' && C<='z')) ? 1 : 0
13.11
#define SWAP(t,x,y) {t tmp; tmp=x; x=y; y=tmp;}
13.12
#include
#include

int main()
{
int *p;
int tmp;
int iLoop;
int iLoop2;

p = (int *)malloc(sizeof(int)*3);

scanf("%d%d%d", p,p 1,p 2);
for(iLoop = 0; iLoop < 2; iLoop )
{
for(iLoop2 = 0; iLoop2 < 2 - iLoop; iLoop2 )
{
if(*(p iLoop2) > *(p iLoop2 1))
{
tmp = *(p iLoop2);
*(p iLoop2) = *(p iLoop2 1);
*(p iLoop2 1) = tmp;
}
}
}
printf("%d %d %d\n", *p, *(p 1), *(p 2));

free(p);
p = NULL;
return 0;
}
字太多了 粘不完

G. 南昌大学C语言的实验报告答案在那里可以找到

亲,我觉得,你直接告诉大家你的实验课题更好一些

H. c语言期末考试试题

去学校抄复印室找找吧。网上其它学校的期末考试题也有,比如南昌大学的:http://wenku..com/view/71eaec8271fe910ef12df886.html

I. C语言程序设计教程(第二版) 周宇 课后答案

二、 1. I love China! printf("we are students.\n") 2. 6 项目实训题参考答案 1.编写一个C程序,输出以下信息: * * * * * * * * * * * * * * * * * * * * I am a student! * * * * * * * * * * * * * * * * * * * * main() { printf("********************\n"); printf(" I am a student!\n "); printf("********************\n"); } 2222....已知立方体的长、宽、高分别是10cm、20cm、15cm,编写程序,求立方体体积。 解: main() { int a,b,c,v; a=10; b=20; c=15; v=a*b*c; printf("v=%d",v); } 本程序运行结果为: v=3000 第第第第2章章章章 编制编制编制编制C程序的基础知识程序的基础知识程序的基础知识程序的基础知识 一 选择题 C B A B A C C 二 操作题 2 21. 3,2,-8,2 3.000000,2.500000,-8.000000 2. ABC DE FGH why is 21+35 equal 52 3. 3 1 4 3 2 3 1 2 4. aa bb cc abc A N 项目实训题 1.定义一个符号常量M为5和一个变量n值为2,把它们的乘积输出。 #define M 5 main() { int n,c; n=2; c=M*n; printf("%d\n",c); } 2.编程求下面算术表达式的值。 (1)x+a%3*(int)(x+y)%2/4,设x=2.5,a=7,y=4.7; (2)(float)(a+b)/2+(int)x%(int)y,设a=2,b=3,x=3.5,y=2.5。 (1)main() { int a=7; float x=2.5,y=4.7; printf("%f\n",x+a%3*(int)(x+y)%2/4); } (2)main() { int a=2,b=3; float x=3.5,y=2.5; printf("%f\n",(float)(a+b)/2+(int)x%(int)y); 第三章第三章第三章第三章 顺序结构程序设计顺序结构程序设计顺序结构程序设计顺序结构程序设计 一 选择题 A C D C C 二 操作题 1. x=3,a=2,b=3 2. z=12.700000 3. 1 2 1 a 2 1 2 三三三三....编程题 编程题编程题编程题编程题 1. 某工种按小时计算工资,每月劳动时间(小时)×每小时工资=总工资,总工资中扣除10%公积金,剩余的为应发工资。编写一个程序从键盘输入劳动时间和每小时工资,打印出应发工资。 解: #include <stdio.h> main() { float sj,gz,yfgz; printf("time,salary:"); scanf("%f,%f",&sj,&gz); yfgz=sj*gz*0.9; printf("total salary:%f\n",yfgz); } 本程序运行结果为: time,salary:4,3<CR> total salary:10.800000 2.编写一个程序求出任意一个输入字符的ASCII码 解: #include <stdio.h> main() { char c; printf("Input a string:"); scanf("%c",&c); printf("%c ASCII is %d\n",c,c); } 本程序运行结果为: Input a string:a<CR> a ASCII is 97 3、编写一个程序用于水果店售货员算帐:已知苹果每斤2.50元,鸭梨每斤1.80元,香蕉每斤2元,橘子每斤1.6元,要求输入各类水果的重量,打印出应付第四章第四章第四章第四章 选择结构程序设计选择结构程序设计选择结构程序设计选择结构程序设计 一、略 二、B B A B C B A 三、1. 1 0 2. 2 3 2 2 3. 10 20 0 4. ch>=’A’&&ch<=’Z’||ch>=’a’&&ch<=’z’ ch>=’0’&&ch<=’9’ ch==’ ’ 5. -1 四、上机操作 1. 从键盘输入一个英文字母,如果是大写字母,则将它变为小写字母输出;如果是小写字母,则将其变为大写字母输出。 #include<stdio.h> main() {char ch; ch=getchar(); if(ch>='A'&&ch<='Z') ch+=32; else if(ch>='a'&&ch<='z') ch-=32; putchar(ch); putchar('\n'); } 2. 根据输入的x值依据下列表达式,计算y的值。 2x (x>-1) y = 3 (x=-1) 4+x (x<-1) 解: main() { float x,y; scanf("%f",&x); if(x>-1) y=2*x; else if(x==1) y=3; else y=4+x; printf("y=%f",y); } 本程序运行结果为: -2<CR> y=2.000000 3.编写程序,输入一个整数,判断它是奇数还是偶数,若是奇数,输出“Is Odd“;若是偶数,输出“Is Even“。 main() { int x; scanf("%d",&x); if(x%2==0) printf("Is Even\n"); else printf("Is Odd\n"); } 4.设计应用程序,求二次方程ax2+bx+c=0的解。 #include<math.h> main() { float a,b,c,disc,x1,x2,p,q; scanf("%f,%f,%f",&a,&b,&c); if(fabs(a)<=1e-6) printf(" The equation is not a quadratic\n"); else { disc=b*b-4*a*c; if(fabs(disc)< 1e-6) printf("x1=x2=%8.4f\n",-b/(2*a)); else if(disc>1e-6) {x1=(-b+sqrt(disc)/(2*a)); x2=(-b-sqrt(disc)/(2*a)); printf("x1=%8.4f,x2=%8.4f\n",x1,x2); } else { p=-b/(2*a); q=sqrt(-disc/(2*a)); printf("%8.4f+%x8.4fi\n",p,q); printf("%8.4f-%8.4fi\n",p,q);} } } 5555....按托运规则,行李不超过50公斤时,运费为0.15元/公斤,如超过50公斤,超过部分的运费为0.22元/公斤,现有行李w公斤,编写一个程序计算运费。 解: #include <stdio.h> main() { float w,f,x; printf("weight:"); scanf("%f",&w); if(w<=50) x=0.15*w; else x=0.15*50+0.22*(w-50); printf("money:%6.2f yuan\n",x); } 本程序运行结果为: weight:20<CR> money:3.00 yuan weight:60<CR> money:9.70 yuan 6. 某商场给与顾客购物的折扣率如下: 购物金额<200元 不打折 500元>购物金额>=200元 9折 1000元>购物金额>=500元 8折 购物金额>=1000元 7.5折 输入一个购物金额,输出打折率、购物实际付款金额。 #include<stdio.h> main() { float x,y,realx; scanf("%f",&x); if(x<=0) { printf("Error! You input a worry number!\n"); y=0;} else { if(x<200) y=1.0; else if(x<500) y=0.9; else if(x<1000) y=0.8; else y=0.75;} if(y!=0) {realx=x*y; printf("y=%f, the realx=%5.2f\n", y,realx);} } 第五章第五章第五章第五章 循环结构程序设计循环结构程序设计循环结构程序设计循环结构程序设计 一、选择题 C C A A D D第六章第六章第六章第六章 数组数组数组数组 、选择题 D A D A A C C A D 二、程序阅读题 13 13 13 13 13 13第七章第七章第七章第七章 函数函数函数函数 一、选择题 B D C B B D A A D第第第第8888章章章章 指针指针指针指针 一、选择题 D A C C(D) D C D 二、填空题 1. m 2. 指针数组名 3. ABCDCD 4.49 5. 25

热点内容
四川农业大学申请考核博士 发布:2025-10-20 08:58:11 浏览:981
福田雷沃重工本科生待遇怎么样 发布:2025-10-20 08:53:49 浏览:575
华为要本科生吗 发布:2025-10-20 08:25:41 浏览:550
2008年青岛本科生工资 发布:2025-10-20 08:04:24 浏览:444
东北大学艺术考研 发布:2025-10-20 07:38:35 浏览:299
我的大学生活txt 发布:2025-10-20 07:35:28 浏览:25
人民大学外语系考研 发布:2025-10-20 07:31:12 浏览:894
上海交通大学考研辅导班 发布:2025-10-20 07:24:54 浏览:420
华中农业大学细胞生物学考研群 发布:2025-10-20 07:09:36 浏览:558
南京大学2016考研线 发布:2025-10-20 06:43:12 浏览:930