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

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

1.编写函数,打印下列序列0,1,1,2,3,5,8,13,21,34...(斐波那契序列)的前n项

#include <stdio.h>int main() {int x=0,y=1,z,n;scanf("%d",&n);if(n==1)printf("%d\n",x);if(n==2)printf("%d\n%d\n",x,y);if(n>2) {printf("%d\n%d\n",x,y);for(int i=2; i<n; i++) {z=x+y;x=y;y=z;printf("%d\n",z);}}
}

2.编写程序打印下列三角矩阵。要求:下三角矩阵的各行值由名为yanghui的函数来计算完成;打印的行数在主函数中由键盘输入;打印在主函数进行。

1 1

1 2 1

1 3 3 1

1 4 6 4 1 

1 5 10 10 5 1

#include <stdio.h>
#include <stdlib.h>void show(int **arr,int n) {for(int i=0; i<n; i++) {for(int j=0; j<=i; j++)printf("%3d ",arr[i][j]);printf("\n");}
}int main() {int n;scanf("%d",&n);int **arr=(int **)malloc(n*sizeof(int*));for(int i=0; i<n; i++)arr[i]=(int *)malloc(n*sizeof(int));for(int i = 0; i < n; i++)for(int j = 0; j <= i; j++)if(j == 0 || j == i)arr[i][j] = 1;elsearr[i][j] = arr[i - 1][j - 1]+ arr[i - 1][j];show(arr,n);
}

3.编写函数,实现两个字符串变量值的交换。并编写主函数,在其中输入两个字符串,然后调用该函数,最后打印输出交换后的两个字符串变量值。要求:形式参数是指针(最多不超过100个字符)注:不允许用strcpy函数直接拷贝实现,两个字符串长度不一定相等

#include <stdio.h>void swapStrings(char** str1, char** str2) {char* temp = *str1;*str1 = *str2;*str2 = temp;
}int main() {char str1[100], str2[100];scanf("%s",&str1);scanf("%s",&str2);swapStrings(&str1, &str2);printf("%s\n", str1);printf("%s\n", str2);return 0;
}

4.从键盘读入10名评委的评分。扣除一个最高分及一个最低分,然后统计总分,并除以8,最后得到这个选手的最后得分(打分采用百分制)并输出之

#include <stdio.h>int main(){int n=10,max=0,min=999;int score,sum=0;while(n!=0){scanf("%d",&score);if(score>max)max=score;if(score<min)min=score;sum+=score;n--;}sum=sum-max-min;printf("%lf%%",1.0*sum/8*100);
}

5.编写函数(函数名为CreatList),建立一个通讯录链表。该通讯录的信息包括姓名和手机号码。在主函数中读取该链表,并将链表的信息写入文件address.txt中

#include <stdio.h>
#include <stdlib.h>typedef struct node{char name[20];int num;struct node *next;
}node;struct node *CreatList(int n){struct node *head=(struct node*)malloc(sizeof(struct node));head->next=NULL;struct node *pre=head;int i;for(i=0;i<n;i++){struct node *p=(struct node*)malloc(sizeof(struct node));scanf("%s %d",&p->name,&p->num);p->next=pre->next;pre->next=p;}return head->next;
}void writelist(struct node *head){FILE *file;if((file=fopen("address.txt","w"))==NULL){printf("open error");exit(0);}struct node *p=head;while(p!=NULL){fprintf(file,"%s %d",&p->name,&p->num);p=p->next;}fclose(file);
}
http://www.lryc.cn/news/309200.html

相关文章:

  • docker-compose搭建php开发环境
  • 翻译论文:Beating Floating Point at its Own Game: Posit Arithmetic(一)
  • 【数据结构-图论】并查集
  • 云计算时代的运维: 职业发展方向与岗位选择
  • java锁底层概述
  • win10如何添加指纹登陆
  • 足底筋膜炎的症状及治疗
  • udp丢包问题研究
  • 在idea中用模板骨架初始创建maven管理的web项目时没有src有关的目录的解决方案
  • WPF 【十月的寒流】学习笔记(2):MVVM中是怎么实现通知的
  • 数据结构:广义表
  • 你好,C++(18) 到底要不要买这个西瓜?4.1.6 操作符之间的优先顺序
  • C语言 for 循环语句的基本格式是什么?
  • 项目-SERVER模块-日志宏
  • TCP为什么要三次握手?
  • 网络防御第6次作业
  • Jmeter分布式部署
  • Odoo迈入开源第一低代码开发平台的重要里程碑
  • WinForm、Wpf自动升级 AutoUpdater.NET
  • GPU不够用:语言模型的分布式挑战
  • 深入理解Redis中的渐进式Rehash技术
  • 数据结构 栈和队列 力扣例题AC——代码以及思路记录
  • 管理类联考--复试--英文面试--各校英文面试内容
  • Android修行手册-Chaquopy中opencv、numpy的初步应用
  • VBA将当前打开的表格生成PDF图片
  • 解锁AI大模型秘籍:未来科技的前沿探索
  • 一文带你了解MySQL之B+树索引的原理
  • 【Vue】npm run build 打包报错:请在[.env.local]中填入key后方可使用...
  • 中国电子学会2020年06月真题C语言软件编程等级考试三级(含详细解析答案)
  • WPF的DataGrid自动生成中文列头