高级语言期末2010级B卷(软件学院)

1.编写程序根据如下公式计算X的值(精确到1e-5)。

#include <stdio.h>

int main(){
	int i=1;
	double flag=1.0/(2*i-1)*2.0*i/(2*i-1);
	double sum=0;
	while(flag>1e-5){
		sum+=flag;
		i++;
		flag=1.0/(2*i-1)*2.0*i/(2*i-1);
	}
	printf("%lf",sum);
	return 0;
}

2.编写程序,输出一个n行n列矩阵中所有鞍点aij,即元素aij满足下列条件:
1)aij是第i行中所有元素的最小值
2)aij是第j列中所有元素的最大值

#include <stdio.h>
#include <stdbool.h>

int main() {
	int n;
	scanf("%d",&n);
	int a[n][n];
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
			scanf("%d",&a[i][j]);
	int count=0;
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++) {
			bool max=true,min=false;
			for(int k=0; k<n; k++)
				if(a[i][k]<a[j][j])
					min=false;
			for(int k=0; k<n; k++)
				if(a[k][j]>a[i][j])
					max=false;
			if(max&&min) {
				printf("%d\n",a[i][j]);
				count++;
			}

		}
	if(count==0)
		printf("NONE\n");
	return 0;
}

4.编写程序,将一个单链表转换为一个反向的单链表。

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

typedef struct node {
	int key;
	struct node *next;
} node;

struct node* reverse(struct node* head) {
	struct node* dummyhead = (struct node*)malloc(sizeof(struct node));
	dummyhead -> next = NULL;
	while(head != NULL) {
		struct node* temp = head -> next;
		head -> next = dummyhead -> next;
		dummyhead -> next = head;
		head = temp;
	}
	return dummyhead -> next;
}

5.每个教师的信息卡片包括教工号、姓名、职称和学院名称三项,编写程序,由键盘依次输入n个教师的信息,创建一个用于管理教师信息的单链表,如下图所示(必须说明该单链表中每个结点的数据类型定义);并保证添加完0所有信息后,该单链表按照教工号从小到大排序。

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

typedef struct teacher {
	int num;
	char name[30];
	char detail[30];
	struct teacher *next;
} teacher;

struct teacher *create(int n) {
	struct teacher *head=(struct teacher *)malloc(sizeof(struct teacher));
	head->next=NULL;
	struct teacher *pre=head;
	for(int i=0; i<n; i++) {
		struct teacher *p=(struct teacher *)malloc(sizeof(struct teacher));
		scanf("%d %s %s",&p->num,&p->name,&p->detail);
		while(pre->next!=NULL&&pre->next->num<p->num)
			pre=pre->next;
		p->next=pre->next;
		pre->next=p;
		pre=head;
	}
	return head->next;
}
  • 6
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值