- 21
- 0
- 约1.91万字
- 约 36页
- 2016-12-06 发布于重庆
- 举报
C語言课程设计报告电子版
C语言课程设计报告
姓名:张林
班级:计算11—1班
学号:1106010124
(1、)A类基本题
1、围绕着山顶有10个圆形排列的洞,狐狸要吃兔子,兔子说:“可以,但必须先找到我,我就藏身于这十个洞中的某个洞。你从1号洞找,下次隔1个洞(即3号洞)找,第三次隔2个洞(即6号洞)找,再隔3个…以后在这个圆圈中如此类推,次数不限。”但狐狸从早到晚进进出出了1000次,仍没有找到兔子。问兔子究竟藏在哪个洞里?
#includestdio.h
int main()
{int i,m=0,k=1;
int a[10];
for(i=0;i10;i++)
a[i]=i+1;
for(i=0;i1000;i++)
{
m=m+k;
k=k+1;
if(m10)
m=m%10;
if(m==a[m-1])
a[m-1]=0;
}
for(i=0;i10;i++)
{if(a[i]!=0)
printf(兔子在第%d个洞内\n,a[i]);
}
return 0;
}
2、编写名为strdup的函数,此函数使用动态存储分配来产生字符串的副本。
例如调用 p= strdup(str);将为和str相同的字符串分配空间,并且把字符串str的内容复制给新字符串,然后返回指向新字符串的指针,如果非配失败则返回空指针。
#includestdio.h
#includemalloc.h
char * strdup(char t[])
{
char *p;
int i;
p=(char *)malloc(6*sizeof(char));
for(i=0;i10;i++)
{if(t[i]==\n) break;}//开辟新空间
if(i*sizeof(char)6*sizeof(char))
return 0;
else
{for(i=0;i6;i++)
*(p+i)=t[i];
return p;}//是其长度和原来的相同
}
void jiancha(char *p)
{
int i;
if(p==0)
printf(failure\n);
else
{
printf(copy:);
for(i=0;i6;i++)
printf(%c,p[i]);//输出
}
已知一个链表中存储了若干名学生的信息,每名学生的信息包括:学号、英语成绩、数学成绩、计算机成绩。现编写一个函数search(),要求根据输入的学生学号,输出他的各科成绩。
#includestdio.h
struct student
{
int num;
float English,math,Computer;
struct student *next;
};
int search(struct student *head,int num)
{
struct student *p1;
if(head==NULL)
{
printf(\nlist null!\n);
return 0;
}
p1=head;
while(num!=p1-num p1-next!=NULL)
{
p1=p1-next;
}
if(num==p1-num)
printf(\nnum:%d\nEglish:%f\nmath:%f\nComputer:%f\n,p1-num,p1-English,p1-math,p1-Computer);
else
printf(\n%d not been found!\n,num);
return 0;
}
void main()
{int num;
struct student a,b,c,d,*head,*p;
a.num=01;a.English=79;a.math=79;a.Computer=77;
b.num=02;b.English=97;b.math=89;b.Computer=68;
c.num=03;c.English=52;c.math=99;c.Computer=54;//输入三个学生信息
head=a;
a.next=b;
b.next=c;
c.next=NULL;
p=head;//连接
do
{
printf(%d %f %f %f\n,p-num,p-English,p-math,p-Computer);
p=p-next;
}while(p!=NULL);
printf
您可能关注的文档
最近下载
- 音体美教学常规要求.doc VIP
- (2025)新课标《义务教育数学课程标准(2022年版)》测试题(附含答案) .pdf VIP
- 质量工程师中级培训教程.doc VIP
- 高中英语(北师大版)必修3—单词表.pdf VIP
- Unit 1 Time to Relax (第1课时) Section A 1a- 2d 课件 2026年春人教版英语八年级下册.pptx VIP
- QE质量工程师培训完整版教材.ppt VIP
- 杜曼教育——如何教宝宝学数学.pdf VIP
- 香港小学中文修辞手法练习.pdf VIP
- 2025-2026学年初中数学八年级上册(2024)沪教版(五四制)(2024)教学设计合集.docx
- GNSS接收机抗干扰技术研究.pptx VIP
原创力文档

文档评论(0)