云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 大学大一c语言程序设计实验室上机题全部代码答案(实验报告)

大学大一c语言程序设计实验室上机题全部代码答案(实验报告)

  • 62 次阅读
  • 3 次下载
  • 2025/6/14 19:21:43

#include #include #include

void search(char *s1, char *s2, char *s3) {

char *p;

int word,i,m,n; char a[20]; p=s1; s3[0]='\\0';

while (*p!='\\0') {

word=0;

for (i=0;p[i]!='\\0';i++)//记录单词的长度i {

if (p[i]!=' '&&word==0) { word=1; m=i; }

else if (p[i]==' '&&word==1) { n=i; break; } }

if (p[i]=='\\0'&&word==1) n=i;

if (word==1) {//将单词复制到atemp中 strncpy(a,p+m,n-m); a[n-m]='\\0'; //puts(s3);

char *pfind;// strstr:找出atemp字符串在s2字符串中第一次出现的位置。

if ( (pfind=strstr(s2,a))!=NULL ) { // finded

// 只是找到包含,如果完全一致,应该将找到对应的单词取出来再比较

if ( *(pfind+strlen(a))==' ' || *(pfind+strlen(a))=='\\0' ) if (strlen(a)>strlen(s3)) strcpy(s3,a); }

p=p+n;

}

else break; } }

main() {

char *s1=\char *s2=\ char s3[20]; search(s1,s2,s3); printf(\}

实验8-3:

编写一个主函数,测试上述两个函数的正确性。 结果如上两题所示。

实验8-4:

输入一个字符串,内有数字和非数字字符,例如: A123cdf 456.78cpc876.9er 849.1 将其中连续的数字作为一个实数,依次存放到一数组a中。例如123存放在a[0],456.78存放在a[2],依次类推,统计共有多少个数,并输出这些数。

源代码:

#include

void f(char *sp,float b[]) { char *p; float value; int power,i=0,j=0; p=sp; while(*p) { for(;!(*p>='0'&&*p<='9');p++) value=0; for(value=0;(*p>='0'&&*p<='9');p++,i++) value=value*10+*p-'0'; if(*p=='.') p++; for(power=1;(*p>='0'&&*p<='9');p++,i++) { value=value*10+*p-'0'; power=power*10; }

value=value/power; b[j++]=value; } printf(\数字个数为:%d\\n\}

void main() { int j; float b[4]={0}; char *a=\ f(a,b); for(j=0;j<4;j++) printf(\}

实验9-1:

编写一个建立单链表的函数,设链表的表元素信息包含学号、姓名、一门课的成绩;写一个按照学号查学生成绩的函数;最后写一个主函数,它先调用建立函数,再调用查询函数,显示查到学生的姓名和成绩。

源代码:

#include struct student { int num; char name[20]; float score;

}stu[4]={{1,\main() { int i,j; printf(\请输入学号:\\n\ scanf(\ for(j=0;j<4;j++) if(stu[j].num==i) printf(\}

实验9-2:

编一程序,能把从终端输入的一个字符串中的小写字母全部转换成大写字母,要求输入的字符的同时指定该字符在字符串中的序号(即字符在字符串中的顺序号,例如第1个字符的序号为1),字符和序号存入结构体中,字符串存入结构体数组中,然后显示结构体数组的结

果(用字符!表示输入字符串的结束)。

源代码:

#include struct str { char a; int num; }s[10]; main() { int i=0; printf(\请输入字母,以!为结束标志\\n\ while(1) { scanf(\ if(s[i].a!='!') s[i].num=i+1; else break; if(s[i].a>'Z') s[i].a=s[i].a-32; printf(\ i++; } }

实验9-3:

在本实验的实验内容1的基础上,实现在链表元素index之前插入元素的操作Insert( struct node *head, int index)和删除指定位置元素的操作Delete( struct node * head, int index),并编写主函数测试。

源代码:

#include #include #include #include struct student {

char name[15]; char num[15]; char risk[15];

struct student *next; };

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

#include #include #include void search(char *s1, char *s2, char *s3) { char *p; int word,i,m,n; char a[20]; p=s1; s3[0]='\\0'; while (*p!='\\0') { word=0; for (i=0;p[i]!='\\0';i++)//记录单词的长度i { if (p[i]!=' '&&word==0) { word=1; m=i; }

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com