printf("第%d个整数为:
%d\n",i+1,a[i]);
return0;
}
2.完成encrypt函数,实现加密功能:
将字符串中所有小写英文字母循环加密。
如a到b,
b到c,…,z到a。
如输入zyhavealittleapple!
,输出为:
azibwfbmjuumfbqqmf!
#include
#include
voidencrypt(char*s)
{
}
intmain()
{
chart1[80],ch;
gets(t1);
printf("\ntheoriginaldatais:
%s",t1);
encrypt(t1);
printf("\ntheresulteddatais:
%s",t1);
printf("\n");
return0;
}
3.用选择法实现对10个整数按从小到大的顺序排序输出(要求完成sort函数)。
#include
intmain()
{
inta[10],i,j;
voidsort(int*);
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("\ntheoriginaldatais:
");
for(i=0;i<10;i++)printf("%d",a[i]);
sort(a);
printf("\ntheresultdatais:
");
for(i=0;i<10;i++)
printf("%d",a[i]);
puts("");
return0;
}
voidsort(int*p)
{
}
4.编写一个函数实现字符串复制功能,不能使用strcpy函数。
(完成copy_string函数)
#include
intmain()
{
chara[100],b[20];
voidcopy_string(char*,char*);
gets(b);
printf("\ntheoriginaldatais:
%s",b);
copy_string(a,b);
printf("\ntheresultdatais:
%s\n",a);
return0;
}
voidcopy_string(char*p,char*q)
{
}
5.完成fun函数:
统计tt所指字符串中'a'到'z'共26个小写字母各自出现的次数,并依此放在pp所指数组中。
例如:
当输入abcdefgabcdeabc后,程序的输出结果应该为:
3332211000000000000
#include
voidfun(char*tt,intpp[])
{
}
voidmain()
{
charaa[1000];
intbb[26],k;
printf("\npleaseenteracharstring:
");
scanf("%s",aa);
fun(aa,bb);
for(k=0;k<26;k++)
printf("%d",bb[k]);
printf("\n");
}
6.用冒泡法实现对10个整数按从大到小的顺序排序输出(完成sort函数)。
#include
intmain()
{
inta[10],i,j;
voidsort(int*);
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("\ntheoriginaldatais:
");
for(i=0;i<10;i++)printf("%d",a[i]);
sort(a);
printf("\ntheresultdatais:
");
for(i=0;i<10;i++)
printf("%d",a[i]);
puts("");
return0;
}
voidsort(int*p)
{
}
7.编写函数:
将ss所指字符串中所有下标为奇数位置上的字母转换为大写(若该位置上不是字母,则不转换)。
如输入:
iamalittle,littleapple!
,变换后为:
iaMALiTtLe,LiTtLeaPpLe!
#include
#include
#defineMAX100
voidfun(char*ss)
{
}
voidmain()
{
chartt[51];
printf("inputastringwithin50characters:
\n");
gets(tt);
printf("\n\nafterchanging,thestring\n\"%s\"",tt);
fun(tt);
printf("\nbecomes\n\"%s\"",tt);
printf("\n");
}
8.有一篇文章,共有4行,每行有10个字符。
要求分别统计出其中英文大写字符、小写字母、数字、空格以及其他字符的个数。
(完成count函数)
#include
intmain()
{
voidcount(char(*p)[10],int[]);
charstr[4][10];
intwzxmt[5]={0,0,0,0,0};//分别统计大写、小写、数字、空格、其他字符个数
printf("input4string:
\n");
for(inti=0;i<4;i++)
gets(str[i]);
count(str,wzxmt);
printf("\ntheresultisbigcharacternis:
%d",wzxmt[0]);
printf("\ntheresultislittlecharacternis:
%d",wzxmt[1]);
printf("\ntheresultisdigitcharacternis:
%d",wzxmt[2]);
printf("\ntheresultisspacecharacternis:
%d",wzxmt[3]);
printf("\ntheresultisothercharacternis:
%d",wzxmt[4]);
return0;
}
voidcount(char(*p)[10],intwzxmt[])
{
}
9.从键盘输入5个学生的信息(包括姓名,成绩),存到磁盘文件上。
然后再从磁盘文件上读取第1,3,5个学生数据输入计算机,并在屏幕上显示出来。
要求完成save函数和read函数。
#include
#include
#defineN5
structStudent
{
charname[10];
intsocre;
}stud[N];
voidsave()
{
}
voidread()
{
}
intmain()
{
printf("pleaseenterdataofstudent:
\n");
for(inti=0;iscanf("%s,%d",stud[i].name,&stud[i].socre);
save();
read();
return0;
}
10.从键盘上读入3个字符串,对它们按字母大小的升序排序,然后把排好序的字符串送到磁盘文件中保存,把文件保存到d盘根目录下,完成write函数。
#include
#include
#include
voidwrite(char(*st)[20],FILE*fp1)
{
}
voidoutput(FILE*fp2)
{
charbuf[30];
if((fp2=fopen("d:
\\file.txt","r"))==NULL)
{printf("can'topenfile\n");
exit(0);
}
while(fgets(buf,20,fp2))
printf("%s",buf);
fclose(fp2);
}
intmain()
{
FILE*fp;
chara[3][20],t[10];
inti,j,k;
printf("Enterthreestrings:
\n");
for(i=0;i<3;i++)
gets(a[i]);
write(a,fp);
output(fp);
return0;
}
11.从键盘输入两个字符串,分别保存在磁盘文件“file1”和“file2”中,完成hebing函数,要求把两个文件中的信息合并(按字母顺序排序),输出到一个新文件“file3”中去。
(file1、file2和file3都存放在d盘根目录下)
#include
#include
voidcreatfile()
{
FILE*fp;
charst[20];
printf("输入第一个字符串:
");
gets(st);
if((fp=fopen("d:
\\file1.txt","w"))==NULL)
{printf("cannotopenfile");
exit(0);
}
fputs(st,fp);
fclose(fp);
printf("\n输入第二个字符串:
");
gets(st);
if((fp=fopen("d:
\\file2.txt","w"))==NULL)
{printf("cannotopenfile");
exit(0);
}
fputs(st,fp);
fclose(fp);
}
voidhebing(charst[],intn)
{
}
voidoutput(FILE*fp1,intn)
{
charch;
if((fp1=fopen("d:
\\file3.txt","r"))==NULL)
{printf("cannotopenfile");
exit(0);
}
printf("\n");
while((ch=fgetc(fp1))!
=EOF)
putchar(ch);
printf("\n");
fclose(fp1);
}
intmain()
{
FILE*fp;
inti,j,n,i1;
charc[100],t,ch;
creatfile();
if((fp=fopen("d:
\\file1.txt","r"))==NULL)
{printf("\ncannotopenfile\n");
exit(0);
}
printf("file1:
\n");
for(i=0;(ch=fgetc(fp))!
=EOF;i++)
{
c[i]=ch;
putchar(c[i]);
}
fclose(fp);
i1=i;
if((fp=fopen("d:
\\file2.txt","r"))==NULL)
{
printf("\ncannotopenfile\n");
exit(0);
}
printf("\nfile2:
\n");
for(i=i1;(ch=fgetc(fp))!
=EOF;i++)
{
c[i]=ch;
putchar(c[i]);
}
fclose(fp);
hebing(c,i);
printf("\nfile3:
\n");
output(fp,i);
return0;
}
12.写一个函数,完成将任意一个数组中的值按逆序重新存放。
(数组长度不超过6位)
要求:
数组内容的内容输入和重新存放后的输出都要在主函数中实现。
如:
输入内容为5个整数,分别为86541,重新存放后输出为:
theresultis1,4,5,6,8。
13.写一个判断素数的函数,在主函数输入一个整数,是素数时输出yes,否则输出no,结果要求在主函数中输出。
14.用递归调用的方法求n!
。
如:
输入为5,输出为5!
=120。
15.编写一个函数,实现在一个升序排列的整型数组{1,3,5,7,14,23,45,87,155,231};中插入任意一个整数的功能,保持整型数组仍然升序排列,并在main函数中调用此函数,输入数据和最后输出都在主函数中实现。
#include
inta[11]={1,3,5,7,14,23,45,87,155,231};
intmain()
{
intc,i;
voidfun(inta[],intc);
printf("inputaninteger:
");
scanf("%d",&c);
fun(a,c);
for(i=0;i<11;i++)
printf("%d",a[i]);
printf("\n");
return0;
}
voidfun(inta[],intt)
{
}
16.输入两个整数,要求用两个函数求出其最大公约数和最小公倍数,最大公约数和最小公倍数都在主函数中输出。
如:
输入36和60,输出为:
zdgys=12,zxgbs=180
17.建立动态数组,输入5个学生的成绩,统计低于60分的学生成绩的个数,要求输入和输出功能在主函数中完成。
18.输入4个整数,找出其中最大的数。
用函数的嵌套调用来处理。
19.按以下递归公式求函数的值。
例如,当给n输入5时,输出为resultis18,(要求用递归实现,并且输入和输出都要在主函数中实现)。
20.用递归法将一个整数n转换成字符串。
(n为不超过6为的整数)如输入为483,输出为:
转换后的字符串为:
483;如输入为-13579,输出为:
转换后的字符串为:
-13579。
注意:
输入和输出都要在主函数中实现。
21.编写一个函数,用来分别求数组score_1(有5个元素)和数组score_2(有10个元素)各元素的平均值。
要求:
输入和输出都要在主函数中实现。
如:
输入第一个数组内容为:
12345,第二个数组内容为:
2468101214161820,输出分别为3和11。
22.编写一个函数,实现将两个字符串连接起来,并在main函数中调用此函数,不要调用系统提供的strcat函数。
(两个字符串长度之和不超过100)
如输入第一个字符串为ILOVE,第二个字符串为:
mymotherland,则输出为ILOVEmymotherland。
23.有一个一维数组score,内放10个学生成绩,编写完成ave函数求平均成绩,并将10个成绩中不及格(小于60)的成绩和该成绩在数组中的序号输出。
#include
intmain()
{
voidave(inta[10]);
inta[10],i;
for(i=0;i<10;i++)
scanf("%d",&a[i]);
ave(a);
return0;
}
voidave(inta[10])
{
}
24.编写完成fun函数,比较两个字符串的大小,并在main函数中调用此函数,不要调用strcmp函数。
要求:
输入和输出都要在主函数中实现。
如:
根据输入不同输入内容,对应输出“两个字符串相等”、“第一个字符串大”、“第二个字符串大”。
#include
#include
intfun(chara[],charb[])
{
}
intmain()
{
chara[100],b[100],i;
gets(a);
gets(b);
i=fun(a,b);
switch(i)
{case0:
printf("第一个字符串大\n");break;
case1:
printf("第二个字符串大\n");break;
default:
printf("两个字符串相等\n");
}
return0;
}
25.编写一个函数,将一个字符串中的原音字母赋值到另一个字符串中,并在main函数中调用此函数,输入数据和最后输出都在主函数中实现。
26.编程实现:
编写完成retu函数,实现统计第二个字符串在第一个字符串中出现的次数,在主函数中调用统计函数并输出结果。
如:
第一个字符串为sdjfzhyishgzhyzhyiszdhxnwzxmt,第二个字符串为zhy,输出结果为:
3
#include
#include
intmain()
{
intretu(chara[],charb[]);
charc[200],d[100];
gets(c);
gets(d);
printf("出现的次数为:
%d\n",retu(c,d));
return0;
}
intretu(chara[],charb[])
{
}
27.有3个学生,每个学生的数据包括学号、姓名、3门课程的成绩,从键盘输入3个学生数据,要求完成max函数和print函数,找到并输出平均成绩最高分的学生的信息(包括学号、姓名、3门课程成绩、平均分数)(用结构体知识)。
#include
#defineN3
structStudent
{
intnum;
charname[20];
floatscore[3];
floataver;
};
intmain()
{
voidinput(structStudentstu[]);
structStudentmax(structStudentstu[]);
voidprint(structStudentstu);
structStudentstu[N],*p=stu;
input(p);
print(max(p));
return0;
}
voidinput(structStudentstu[])
{
inti;
printf("请输入各个学生的信息:
学号、姓名、三门课成绩:
\n");
for(i=0;i{
scanf("%d%s%f%f%f",&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
stu[i].aver=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3;
}
}
structStudentmax(structStudentstu[])
{
}
voidprint(structStudentstu)
{
}
28.设计候选人得票统计程序,有3个侯选人(分别是库里、哈登、勒布朗),共有50张选票,最后统计出各人的得票结果。
(完成count函数)
#include
#include
structperson
{charname[20];
intcnt;
};
voidcount(structpersonst[],char*tt[])
{
}
voidoutput(structpersonst[])
{
inti;
printf("\n");
for(i=0;i<3;i++)
printf("\n%15s%5d张票",st[i].name,st[i].cnt);
}
intmain()
{
char*xp[50]={"库里","哈登","勒布朗","勒布朗","库里","库里","勒布朗","库里","勒布朗","库里","库里","库里","库里","库里","库里","库里","库里","库里","库里","库里","库里","库里","勒布朗","勒布朗","哈登","勒布朗","勒布朗","库里","库里","哈登","库里","哈登","库里","库里","库里","库里","库里","哈登","哈登","哈登","哈登","库里","库里","哈登","哈登","哈登","库里","库里","库里","库里"};
structpersonleader[3]={"库里",0,"哈登",0,"勒布朗",0};
count(leader,xp);
output(leader);
printf("\n");
return0;
}
29.学生记录由学号和成绩组成,N名学生的数据已经在主函数中放入结构体数组,编写完成fun函数,把低于平均分的学生数据放在b所指的数组中,低于平均分的学生人数通过形参n返回,平均分通过函数值返回。
#include
#defineN8
typedefstruct{
charnum[10];
doubles;
}STREC;
doublefun(STREC*a,STREC*b,int*n)
{
}
voidmain()
{
STRECs[N]={{"gao05",85},{"gao03",76},{"gao02",69},{"gao04