当前位置: 首页 > news >正文

高级语言期末2009级B卷(计算机学院)

1.编写一个名为mystrcpy的函数,实现将字符串str1的偶数位子的字符的拷贝到另一个字符串str2中。并编写主函数,在主函数中从键盘读入一个长度<100的字符串str1,然后调用函数mystrcpy;最后输出str2,例如,读入“abcdefgh”,则输出"bdfh".

#include <stdio.h>void mystrcpy(char *str1,char *str2){int i=0,j=0;while(str1[i]!='\0'){if((i+1)%2==0){str2[j]=str1[i];j++;}i++;}
}int main(){char str1[]="abcdefgh";char str2[100];mystrcpy(str1,str2);printf("%s",str2);
}

2.编写一个函数,将一维数组转换成一个N阶方阵(二维数组),矩阵的行数由函数的参数指定。然后再main()中调用该函数,并打印输出该仿真的对角线上的值

#include <stdio.h>
#include <stdlib.h>
#include <math.h>void changesqure(int *a,int n,int **arr,int size){int i,j=0,k=0;for(i=0;i<n;i++){arr[j][k]=a[i];k++;if(k!=0&&k%size==0){j++;k=0;}}
}int main(){int a[]={1,2,3,4,5,6,7,8,9};int n = sizeof(a)/sizeof(a[0]);int size=sqrt(n);int **arr = (int **)malloc(size*sizeof(int *));int i,j;for(i=0;i<size;i++)arr[i]=(int *)malloc(size*sizeof(int));changesqure(a,n,arr,size);for(i=0;i<size;i++){for(j=0;j<size;j++)if(i==j)printf("%d ",arr[i][j]);printf("\n");}
}

3.编写一个函数,求2个数的最小公倍数并输出。要求在主函数中从键盘读入2个正的int型整数,求他们的最小公倍数并输出

#include <stdio.h>int gcd(int x,int y) {if(y==0)return x;return 1.0*x*y/gcd(y,x%y);
}

4.某班学生信息包括学号(字符串,长度不超过8位)、姓名(没有空格的字符串,长度不超过20位)和两门课程的成绩。请写出学生结构体,并编写函数CreatList,创建学生链表

#include <stdio.h>
#include <stdlib.h>typedef struct student{char num[8];char name[20];int score1;int score2;struct student *next;
}student;struct student *CreatList(int n){struct student *head=(struct student*)malloc(sizeof(struct student));head->next=NULL;struct student *pre=head;int i;for(i=0;i<n;i++){struct student *p=(struct student*)malloc(sizeof(struct student));scanf("%s %s %d %d",&p->num,&p->name,&p->score1,&p->score2);p->next=pre->next;pre->next=p;}return head->next;
}

5.将上题的学生链表信息读出并写入文件student.txt

#include <stdio.h>
#include <stdlib.h>typedef struct student{char num[8];char name[20];int score1;int score2;struct student *next;
}student;void writelist(struct student *head){FILE *file;if((file=fopen("student.txt","w"))==NULL){printf("open error");exit(0);}struct student *p=head;while(p!=NULL){fprintf(file,"%s %s %d %d",&p->num,&p->name,&p->score1,&p->score2);p=p->next;}fclose(file);
}
http://www.lryc.cn/news/308884.html

相关文章:

  • c# using 用法
  • 【Django】执行查询—跨关系查询中的跨多值关联问题
  • Spring八股 常见面试题
  • 今年面试潮,说实话这个开发岗能不能冲?
  • 【前端素材】推荐优质在线花卉商城电商网页Flowery平台模板(附源码)
  • ★【递归】【构造二叉树】Leetcode 106.从中序与后序遍历序列构造二叉树
  • linux检测和重启python脚本
  • HTML+CSS+JS:花瓣登录组件
  • Unity中URP下实现水体(水面反射)
  • 基于FastJson实现Json数据文件导入导出解析
  • JVM内存分配与垃圾收集流程
  • 【python】yaml转成json
  • css5定位
  • 【解决】修改 UI界面渲染层级 的常见误区
  • 蓝桥杯练习系统(算法训练)ALGO-995 24点
  • 汽车电子笔记:BootLoader升级过程疑难问题解决方式(Bootloader响应10 02 + 刷死拯救机制)
  • 高级RAG:揭秘PDF解析
  • Android之UI Automator框架源码分析(第九篇:UiDevice获取UiAutomation对象的过程分析)
  • 【C语言】指针初阶2.0版本
  • 小红书关键词爬虫
  • 网络爬虫的危害,如何有效的防止非法利用
  • 2024/2/29 备战蓝桥杯 6-1 二分
  • 浅析ARMv8体系结构:原子操作
  • 综合练习(二)
  • sql-labs第46关(order by盲注脚本)
  • 13款可以轻松上手画图软件推荐
  • vue实现商品评分效果(通过插件实现)
  • SpringBoot 手写 Starter
  • C++ 学习笔记(Structured bindings)
  • K8S常用kubectl命令汇总(持续更新中)