C语言编程题1Word文档下载推荐.docx
- 文档编号:21719242
- 上传时间:2023-01-31
- 格式:DOCX
- 页数:22
- 大小:20.81KB
C语言编程题1Word文档下载推荐.docx
《C语言编程题1Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《C语言编程题1Word文档下载推荐.docx(22页珍藏版)》请在冰豆网上搜索。
);
scanf("
%ld"
&
s);
fun(s,&
t);
Theresultis:
%ld\n"
t);
3、设N是一个四位数,它的9倍恰好是其反序数(例如:
123的反序数是321),编程,输出所有满足条件的N。
控制语句)
{
inta=1,b,c,d;
for(d=0;
d<
=9;
d++)
for(b=0;
b<
=1;
b++)
for(c=0;
c<
c++)
if(9000*a+900*b+90*c+9*d==1000*d+100*c+10*b+a)
%d\n"
1000*a+100*b+10*c+d);
4、编程,求解下列算式中各字母所代表的数字并输出。
PEAR
- ARA
──────
PEA
intp,e,a,r;
for(p=1;
p<
p++)
for(e=0;
e<
e++)
for(a=1;
a<
a++)
for(r=0;
r<
r++)
if(1000*p+100*e+10*a+r-101*a-10*r==100*p+10*e+a)
p=%d;
e=%d;
a=%d;
r=%d\n"
p,e,a,r);
5、有一个字符串,包括n个字符。
写一个函数,将此字符串从第m个字符开始的全部字符复制成另一个字符串。
要求在主函数输入字符串及m值并输出复制结果。
控制语句、字符串、指针)
ctype.h>
main()
{intm;
char*str1[80],*str2[80];
Inputastring(length<
80:
%s"
str1);
\nWhichcharacterstartingfrom?
%d"
m);
if(strlen(str1)<
m)
\nErrorinput!
else
{copystr(str1,str2,m);
\nResultis:
%s"
str2);
)
copystr(p1,p2,m)
char*p1,*p2;
intm;
intn;
n=0;
while(n<
=m-1)
{n++;
p1++;
while(*p1!
='
\0'
{*p2=*p1;
p2++;
*p2='
;
6、编一程序,能把从终端读入的一个字符中的小写字母全部转换成大写字母,然后输出到一个磁盘文件“test”中保存(用字符!
表示输入字符串的结束)。
文件)
{FILE*fp;
charstr[100];
inti=0;
if((fp=fopen("
test"
"
w"
))==NULL)
{printf("
Can'
topenthisfile.\n"
exit(0);
Inputastring:
\n"
gets(str);
while(str[i]!
!
'
{if(str[i]>
a'
&
str[i]<
z'
str[i]=str[i]-32;
fputc(str[i],fp);
i++;
fclose(fp);
r"
can'
topentestr\n"
fgets(str,strlen(str)+1,fp);
Outputis:
str);
7、编写函数fun,函数的功能是:
将M行N列的二维数组中的字符数据,按列的
顺序依次放到一个字符串中。
例如,二维数组中的数据为:
WWWW
SSSS
HHHH
则字符串中的内容应是:
WSHWSHWSH。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入
你编写的若干语句。
数组、指针)
给定源程序:
#defineM3
#defineN4
voidfun(chars[][N],char*b)
inti,j,n=0;
for(i=0;
i<
N;
i++)/*请填写相应语句完成其功能*/
b[n]='
{chara[100],w[M][N]={{'
W'
'
},{'
S'
H'
}};
inti,j;
Thematrix:
\n"
i<
M;
i++)
{for(j=0;
j<
N;
j++)printf("
%3c"
w[i][j]);
fun(w,a);
TheAstring:
puts(a);
\n\n"
for(j=0;
j<
M;
j++)
{
b[n]=s[j][i];
n=i*M+j+1;
8、编写函数fun,函数的功能是:
统计各年龄段的人数。
N个年龄通过调用随机
函数获得,并放在主函数的age数组中;
要求函数把0至9岁年龄段的人数放在d[0]
中,把10至19岁年龄段的人数放在d[1]中,把20至29岁年龄段的人数放在d[2]中,
其余依此类推,把100岁(含100)以上年龄的人数都放在d[10]中。
结果在主函数
中输出。
注意:
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入
#defineN50
#defineM11
voidfun(int*a,int*b)
doublernd()
{statict=29,c=217,m=1024,r=0;
r=(r*t+c)%m;
return((double)r/m);
{intage[N],i,d[M];
i++)age[i]=(int)(115*rnd());
Theoriginaldata:
i<
i++)printf((i+1)%10==0?
%4d\n"
:
%4d"
age[i]);
fun(age,d);
10;
i++)printf("
%4d---%4d:
%4d\n"
i*10,i*10+9,d[i]);
Over100:
d[10]);
inti,j;
for(i=0;
i++)b[i]=0;
N;
i++){
j=a[i]/10;
if(j>
10)b[M-1]++;
elseb[j]++;
9、编写函数fun,函数的功能是:
将M行N列的二维数组中的数据,按行的顺序
依次放到一维数组中,一维数组中数据的个数存放在形参n所指的存储单元中。
33333333
44444444
55555555
则一维数组中的内容应是:
333333334444444455555555。
勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入
voidfun(int(*s)[10],int*b,int*n,intmm,intnn)
{intw[10][10]={{33,33,33,33},{44,44,44,44},{55,55,55,55}},i,j;
inta[100]={0},n=0;
);
3;
{for(j=0;
4;
j++)printf("
%3d"
w[i][j]);
fun(w,a,&
n,3,4);
TheAarray:
n;
i++)printf("
a[i]);
inti,j,k;
mm;
nn;
j++){
k=i*nn+j;
b[k]=s[i][j];
*n=mm*nn;
10、N名学生的成绩已在主函数中放入一个带头节点的链表结构中,h指向链表的头
节点。
请编写函数fun,它的功能是:
找出学生的最高分,由函数值返回。
注意:
勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入
链表)
stdlib.h>
#defineN8
structslist
{doubles;
structslist*next;
};
typedefstructslistSTREC;
doublefun(STREC*h)
STREC*creat(double*s)
{STREC*h,*p,*q;
inti=0;
h=p=(STREC*)malloc(sizeof(STREC));
p->
s=0;
while(i<
N)
{q=(STREC*)malloc(sizeof(STREC));
q->
s=s[i];
i++;
p->
next=q;
p=q;
next=0;
returnh;
outlist(STREC*h)
{STREC*p;
p=h->
next;
head"
do
->
%2.0f"
p->
p=p->
while(p!
=0);
{doubles[N]={85,76,69,85,91,72,64,87},max;
STREC*h;
h=creat(s);
outlist(h);
max=fun(h);
max=%6.1f\n"
max);
doublemax=h->
s;
STREC*p;
while(p)
{if(p->
s>
max)
max=p->
returnmax;
11、函数fun的功能是:
将s所指字符串中ASCII值为奇数的字符删除,串中剩余字
符形成一个新串放在t所指的数组中。
例如,若s所指字符串中的内容为:
ABCDEFG12345"
,其中字符A的ASCII码值
为奇数、…、字符1的ASCII码值也为奇数、…都应当删除,其它依此类推。
最后
t所指的数组中的内容应是:
BDF24"
。
函数、字符串、指针)
string.h>
voidfun(char*s,chart[])
chars[100],t[100];
\nPleaseenterstringS:
scanf("
s);
fun(s,t);
\nTheresultis:
%s\n"
t);
inti,j=0;
strlen(s);
i++)if(s[i]%2==0)t[j++]=s[i];
t[j]=0;
12、学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组
s中,请编写函数fun,它的功能是:
把分数最低的学生数据放在b所指的数组中,
分数最低的学生可能不止一个,函数返回分数最低的学生的人数。
勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入
结构体)
#defineN16
typedefstruct
{charnum[10];
ints;
}STREC;
intfun(STREC*a,STREC*b)
{STRECs[N]={{"
GA05"
85},{"
GA03"
76},{"
GA02"
69},{"
GA04"
85},
{"
GA01"
91},{"
GA07"
72},{"
GA08"
64},{"
GA06"
87},
GA015"
GA013"
GA012"
GA014"
91},
GA011"
GA017"
GA018"
GA016"
72}};
STRECh[N];
inti,n;
FILE*out;
n=fun(s,h);
The%dlowestscore:
n);
n;
%s%4d\n"
h[i].num,h[i].s);
out=fopen("
c:
\\test\\out.dat"
fprintf(out,"
h[i].s);
fclose(out);
inti,j=0,min=a[0].s;
if(min>
a[i].s){
j=0;
b[j++]=a[i];
min=a[i].s;
elseif(min==a[i].s)
b[j++]=a[i];
returnj;
13、请编写函数fun,它的功能是:
计算并输出n(包括n)以内能被5或9整除的所有
自然数的倒数之和。
例如,在主函数中从键盘给n输入20后,输出为:
s=0.583333。
要求n的值不大于100。
勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
控制语句、函数)
doublefun(intn)
{intn;
doubles;
\nInputn:
"
n);
s=fun(n);
\n\ns=%f\n"
s);
inti;
doublesum=0.0;
for(i=1;
=n;
if(i%5==0||i%9==0)/*被5或9整除*/
sum+=1.0/i;
returnsum;
14、某班有5个学生,三门课。
分别编写3个函数实现以下要求:
(1)求各门课的平均分;
(2)找出有两门以上不及格的学生,并输出其学号和不及格课程的成绩;
(3)找出三门课平均成绩在85-90分的学生,并输出其学号和姓名
主程序输入5个学生的成绩,然后调用上述函数输出结果。
函数、数组)
#defineSNUM5/*studentnumber*/
#defineCNUM3/*coursenumber*/
/*dispstudentinfo*/
voidDispScore(charnum[][6],charname[][20],floatscore[][CNUM])
\n\nStudentInfoandScore:
SNUM;
i++)
%s"
num[i]);
name[i]);
for(j=0;
CNUM;
j++)
%8.2f"
score[i][j]);
/*calculateallstudentaveragescore*/
voidCalAver(floatscore[][CNUM])
floatsum,aver;
sum=0;
sum=sum+score[j][i];
aver=sum/SNUM;
Averagescoreofcourse%dis%8.2f\n"
i+1,aver);
/*Findstudent:
twocoursesnopass*/
voidFindNoPass(charnum[][6],floatscore[][CNUM])
inti,j,n;
\nTwoCourseNoPassStudents:
if(score[i][j]<
60)
n++;
if(n>
=2)
threecourses85-90*/
voidFindGoodStud(charnum[][6],charname[][20],floatscore[][CNUM])
\nScoreofthreecoursesbetween85and90:
if(sc
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 编程
![提示](https://static.bdocx.com/images/bang_tan.gif)