东华11年复试真题

问题

问题2:求广义的斐波那契数列

/*
广义斐波那契数列

*/
#include <stdio.h>
int function(int n){
	if (n == 1 || n == 2 || n == 3)
		return 1;
	else {
		int a1 = 1;
		int a2 = 1;
		int a3 = 1;
		int a;
		int i;
		for (i = 4; i <= n; i++){
			a = a1 + a2 + a3;
			a1 = a2;
			a2 = a3;
			a3 = a;
		}
		return a;
	}
}
int main(){
	int n;
	scanf("%d", &n);
	int number = function(n);
	printf("%d", number);
	return 0;
}

问题3:从1到55,选出能被3整除,且至少有一位上的数是5的那些数,求出个数

#include <stdio.h>
int function(int s){
	int total = 0;
	while (s){
		if (s % 10 == 5)
			total++;
		 s = s / 10;
	}
	if (total != 0)
		return 1;
	return 0;
}
int main(){
	int i;
	int count = 0;
	for (i = 1; i <= 55; i++){
		if (i % 3 == 0&&function(i)){
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}

问题4:查询成绩最高的学生记录

/*
查询成绩最高的学生记录
注意返回学生实体
*/

#include <stdio.h>
struct student{
	char name[10];
	int grade;
}s[3];
struct student sort(struct student a[3]){
	int i, j;
	struct student temp;
	for (i = 0; i < 3;i++)
	for (j = 0; j < 3 - i - 1; j++){
		if (a[j].grade<a[j + 1].grade){
			temp = a[j];
			a[j] = a[j + 1];
			a[j + 1] = temp;
		}
	}
	return a[0];
}
int main(){
	int i;
	for (i = 0; i < 3; i++)
		scanf("%s%d", &s[i].name, &s[i].grade);
	struct student temp = sort(s);
	printf("%s%d", temp.name, temp.grade);
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值