高级语言程序设计_期末题册_自练(更新中)

2018

A.1

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */


int main(int argc, char *argv[]) {
	int n,i;
	printf("输入一个正整数n\n");
	scanf("%d",&n);
	double s=0;
	for(i=1;i<=n;i++)
		s+=((2*i)/(pow(2*i-1,2)));
	printf("s=%lf",s);
	return 0;
} 

A.2

int mystrcmp(char *str1,char *str2){
	int i=0;
	while(str1[i]!='\0'&&str2[i]!='\0'){
		if(str1[i]>str2[i])
			return 1;
		else if(str1[i]<str2[i])
			return -1;
		else
			i++;
	} 
	if(str1[i]=='\0'&&str2[i]=='\0')
		return 0;
	if(str1[i]!='\0')
		return 1;
	return -1;
}

void mystrcpy(char *str1,char *str2){
	int i=0;
	while(str2[i]!='\0'){
		str1[i]=str2[i];
		i++;
	}
	str1[i]='\0';
}

void sort(char st[][10],int n){
	int i,j;
	char temp[10];
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++){
			if(mystrcmp(st[i],st[j])>0){
				mystrcpy(temp,st[i]);
				mystrcpy(st[i],st[j]);
				mystrcpy(st[j],temp);
			}
		}
}

A.3,B.1

int binarysearch(int a[],int n,int key){
	if(n==-1)
		return -1;
	int mid=n/2;
	if(a[mid]==key)
		return mid;
	else if(a[mid]>key)
		return binarysearch(a,mid-1,key);
	else
		return binarysearch(a+mid+1,n-mid-1,key);
}

A.4

struct student{
	int id;
	char name[10];
	int dscore;
	int escore;
	int tscore;
	struct student *next;
};

struct student *create(){
	FILE *fp;
	if((fp=fopen("2018Exp.txt","r"))==NULL){
		printf("文件打开失败\n"); 
		exit(0);
	}
	struct student *p0=(struct student*)malloc(sizeof(struct student));
	p0->next=NULL;
	struct student *rear=p0;
	while(!feof(fp)){
		struct student *p=(struct student*)malloc(sizeof(struct student));
		fscanf(fp,"%d%s%d%d%d",&p->id,p->name,&p->dscore,&p->escore,&p->tscore);
		rear->next=p;
		p->next=NULL;
		rear=p;
	}
	fclose(fp);
	struct student *head=p0->next;
	free(p0);
	return head;
}

A.5

double total(struct student *p){
	return (0.2*(p->dscore)+0.2*(p->escore)+0.6*(p->tscore));
}

struct student *sort(struct student *head){
	if(head==NULL||head->next==NULL)
		return head;
	struct student* p0=(struct student*)malloc(sizeof(struct student));
	p0->next=head;
	struct student* pre=p0;
	struct student *p1=pre->next;
	struct student *p2=pre->next;
	struct student *end=NULL;
	int flag=1;
	while(flag){
		flag=0;
		while(p2!=end){
			if(total(p1)<total(p2)){
				pre->next=p2;
				p1=p2->next;
				p2->next=p1;
				flag=1;
				pre=p2;
			}
			else{
				pre=p1;
				p1=p2;
			}
			p2=p1->next;
		} 
		end=p1;
	}
	head=p0->next;
	free(p0);
	return head; 
} 

B.2

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define N 10
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int judge(int a[N][N],int i,int j){
	int k,num=0;
	for(k=0;k<N;k++){
		if(a[i][k]>a[i][j])
			return 0;
		if(a[k][j]<a[i][j])
			num++;
	}
	if(num==j/2)
		return 1;
} 

int main(int argc, char *argv[]) {
	int i,j;
	int a[N][N];
	for(i=0;i<N;i++)
		for(j=0;j<N;j++)
			scanf("%d",&a[i][j]);
	for(i=0;i<N;i++)
		for(j=0;j<N;j++){
			if(judge(a,i,j))
				printf("%d",a[i][j]);
		} 
	return 0;
} 

B.3

int del(char a[]){
	if(a[0]=='\0')
		return 1;
	if(a[0]<'0'||a[0]>'9')
		return del(a+1);
	if(a[0]>'0'&&a[0]<='9')
		return (a[0]-'0')*del(a+1);
	if(a[0]=='0')
		return 0;
}

B.4

struct student{
	int id;
	char name[10];
	int dscore;
	int escore;
	int tscore;
	struct student *next;
};

void change(struct student *head){
	FILE *fp;
	if((fp=fopen("2018ExpChange.txt","w"))==NULL){
		printf("文件打开失败");
		exit(0);
	}
	struct student *p=head;
	while(p!=NULL){
		if(p->tscore>=85){
			p->dscore=100;
			p->escore=100;
			fprintf(fp,"%d%s%d%d%d\n",p->id,p->name,p->dscore,p->escore,p->tscore);
		}
		p=p->next;
	}
	fclose(fp);
}

B.5

double total(struct student *p){
	return (0.2*(p->dscore)+0.2*(p->escore)+0.6*(p->tscore));
}

struct student *sort(struct student *head){
	if(head==NULL||head->next==NULL)
		return head;
	struct student* p0=(struct student*)malloc(sizeof(struct student));
	p0->next=head;
	struct student* pre=p0;
	struct student *p1=pre->next;
	struct student *p2=pre->next;
	struct student *end=NULL;
	int flag=1;
	while(flag){
		flag=0;
		while(p2!=end){
			if(total(p1)<total(p2)){
				pre->next=p2;
				p1=p2->next;
				p2->next=p1;
				flag=1;
				pre=p2;
			}
			else{
				pre=p1;
				p1=p2;
			}
			p2=p1->next;
		} 
		end=p1;
	}
	head=p0->next;
	free(p0);
	return head; 
} 

void out(struct student *head){
	head=sort(head);
	FILE *fp;
	if((fp=fopen("2018Exp.txt","w"))==NULL){
		printf("文件打开失败");
		exit(0);
	}
	struct student *p=head;
	while(p!=NULL){
		fprintf(fp,"%d%s%d%d%d\n",p->id,p->name,p->dscore,p->escore,p->tscore);
		p=p->next;
	}
	fclose(fp);
}

2017

A.1

void sort(int a[],int n){
	int i,flag=1,end=n;
	while(flag){
		flag=0;
		for(i=0;i<end;i++){
			if(a[i]>a[i+1]){
				int temp=a[i];
				a[i]=a[i+1];
				a[i+1]=temp;
				flag=1;
			}
		}
		end=i-1;
	}
}

A.2

int mystrlen(char str[]){
	int i=0;
	while(str[i]!='\0')
		i++;
	return i; 
}
 

char *max(char *st[],int n){
	int i,maxlen=0;
	char *maxstr="";
	for(i=0;i<n;i++){
		if(mystrlen(st[i])>maxlen){
			maxlen=mystrlen(st[i]);
			maxstr=st[i];
		} 
	}
	return maxstr;
}

A.3

double f(double x,int n){
	if(n==1);
		return 1;
	if(n==2)
		return x;
	if(n>2)
		return (2*f(x,n-2)+3*f(x-1,n-1));
}

A.4

struct student{
	int num;
	char name[10];
	int MScore;
	int EScore;
	int HScore;
	int FScore;
	struct student *next;
};

double total(struct student *p){
	if(p==NULL)
		return 0;
	return (p->MScore)*0.2+(p->EScore)*0.2+(p->HScore)*0.2+(p->FScore)*0.6; 
}

struct student *create(){
	FILE *fp;
	if((fp=fopen("D:\\2017scores.txt","r"))==NULL){
		printf("Open File ERROR");
		exit(0);
	}
	struct student *head=(struct student*)malloc(sizeof(struct student));
	head->next=NULL;
	struct student *pre,*rear;
	while(!feof(fp)){
		struct student *p=(struct student*)malloc(sizeof(struct student));
		fscanf(fp,"%d%s%d%d%d%d",&p->num,p->name,&p->MScore,&p->EScore,&p->HScore,&p->FScore);	
		pre=head,rear=head->next;
		while(total(rear)>total(p)){
			pre=rear;
			rear=rear->next;
		}
		pre->next=p;
		p->next=rear;
	}
	fclose(fp);
	return head->next;
}

A.5

bool isFail(struct student *p){
	if(p->MScore<60||p->EScore<60)
		return true;
	if(total(p)<60)
		return true;
	return false;	
}

struct student* del(struct student *head){
	if(head==NULL)
		return head;
	struct student *p0=(struct student*)malloc(sizeof(struct student));
	p0->next=head;
	struct student *pre=p0; 
	while(pre!=NULL&&pre->next!=NULL){
		if(isFail(pre->next)){
			struct student *temp=pre->next;
			pre->next=temp->next;
			free(temp);
		}
		pre=pre->next;
	}
	head=p0->next;
	free(p0);
	return head;
}

B.1

void sort(int a[],int *n,int j){
	if(*n<j)
		return;
	int i,end=*n,num=0;
	while(num<j){
		for(i=0;i<end;i++){
			if(a[i]<a[i+1]){
				int temp=a[i];
				a[i]=a[i+1];
				a[i+1]=temp;
			}
		}
		end=i-1;
		num++;
	}
	*n=end;
}

B.2

int mystrlen(char str[]){
	int len=0;
	while(str[len++]!='\0');
	return len;
}

int mystrcmp(char *str1,char *str2){
	int i=0;
	while(str1[i]!='\0'&&str2[i]!='\0'){
		if(str1[i]>str2[i])
			return 1;
		else if(str1[i]<str2[i])
			return -1; 
		i++;
	}
	if(i==mystrlen(str1)&&i==mystrlen(str2))
		return 0;
	else if(i==mystrlen(str1)) 
		return -1;
	else
		return 1; 
}


char *final(char *st[],int n){
	int i;
	char *max="";
	for(i=0;i<n;i++){
		if(mystrcmp(st[i],max)==1)
			max=st[i];
	} 
	return max;
}

B.3

double g(int n,double x){
	if(n==0)
		return 0;
	if(n==1)
		return x+1;
	if(n>2)
		return g(n-2,x-1)+2*g(n-1,x);
}

B.4

struct student{
	int num;
	char name[10];
	int politics;
	int English;
	int math;
	int major;
	struct student *next;
};

struct student *create(){
	struct student *head=(struct student*)malloc(sizeof(struct student));
	head->next=NULL;
	struct student *pre,*rear;
	int i;
	for(i=0;i<30;i++){
		struct student *p=(struct student*)malloc(sizeof(struct student));
		scanf("%d%s%d%d%d%d",&p->num,p->name,&p->politics,&p->English,&p->math,&p->major);
		pre=head;
		rear=head->next;
		while(rear!=NULL&&rear->num<p->num){
			pre=rear;
			rear=rear->next;
		}
		pre->next=p;
		p->next=rear;
	} 
	return head->next;
} 

B.5

int total(struct student *p){
	return (p->politics+p->English+p->major+p->math);
}

bool ispass(struct student *p){
	if(p->politics>=45&&p->English>=45&&p->math>=68&&p->major>=68&&total(p)>=320)
		return true;
	else
		return false;
}

void output(struct student *head){
	if(head==NULL)
		return;
	FILE *fp;
	if((fp=fopen("2017scores.txt","w"))==NULL){
		printf("Open File ERROR!");
		exit(0);
	}
	struct student *p=head;
	while(p!=NULL){
		if(ispass(p))
			fprintf(fp,"%d%s%d%d%d%d",p->num,p->name,p->politics,p->English,p->math,p->major); 
		p=p->next; 
	}
	fclose(fp);
}

2016

A.1

void rev(int a[],int n){
	int i=0;
	while(i<n/2) {
		int temp=a[i];
		a[i]=a[n-i-1];
		a[n-i-1]=temp;
		i++;
	}
}

A.2

int comp(char *a,char *b){
	int i=0,j=0;
	while(a[i++]!='\0');
	while(b[j++]!='\0');
	return abs(i-j);
}

A.3

int breaktime(double x){
	if(x<=5)
		return 1;
	else{
		double x1=2.0*n/5;
		double x2=3.0*n/5;
		return breaktime(x1)+breaktime(x2);
	}
}

A.4

struct student{
	int num;
	char name[10];
	char tel[11];
	struct student *next;
};

struct student *create(int n){
	if(n==0)
		return NULL;
	struct student *p0=(struct student *)malloc(sizeof(struct student));
	p0->next=NULL;
	struct student *pre,*rear;
	int i;
	for(i=0;i<n;i++){
		pre=p0,rear=NULL;
		struct student *p=(struct student*)malloc(sizeof(struct student));
		scanf("%d%s%s",&p->num,p->name,p->tel);
		while(rear!=NULL&&rear->num<p->num){
			pre=rear;
			rear=rear->next;
		}
		pre->next=p;
		p->next=rear;
	}
	return p0->next;
}

A.5

void inputaddress(struct student *head){
	FILE *fp;
	if((fp=fopen("D:\\address.txt","w"))==NULL){
		printf("Open File Error!");
		exit(0);
	}
	struct student *p=head;
	while(p!=NULL){
		char address[50];
		fprintf(fp,"%d%s%s",p->num,p->name,p->tel);
		printf("输入%d%s同学的家庭地址:\n",p->num,p->name); 
		scanf("%s",address);
		fprintf(fp,"%s\n",address);
		p=p->next;
	}
	fclose(fp);
}

B.1

int fac(int n){
	if(n==0)
		return 1;
	return n*fac(n-1); 
}

double f(int n){
	if(n==0)
		return 0;
	return (1.0*n/((n+1)*fac(n+2)))+f(n-1);
} 

B.2

bool isexist(int a[],int n){
	int sum=0;
	int i;
	for(i=0;i<n;i++){
		if(a[i]==sum)
			return true;
		sum+=a[i];
	}
	return false;
}

B.3

int sum(int n){
	if(n==0)
		return 0;
	return n%10+sum(n/10);
}

B.4

struct teacher{
	char name;
	bool sex;
	int age;
};

void create(int n,struct teacher t[]){
	int i;
	printf("请依次输入%d个老师的姓名,性别(男:1,女:0),年龄:\n",n);
	for(i=0;i<n;i++)
		scanf("%s%d%d",t[i].name,&t[i].sex,&t[i].age);
}

B.5

struct teacher{
	char name;
	bool sex;
	int age;
	struct teacher *next; 
};

void output(struct teacher *head){
	FILE *fp;
	if((fp=fopen("output.txt","w"))==NULL){
		printf("Open File ERROR!");
		exit(0);
	}
	struct teacher *p=head;
	while(p!=NULL){
		if(!(p->sex))
			fprintf(fp,"%s 女 %d",p->name,p->age);
		p=p->next; 
	}
	fclose(fp);
}

2016-唐班

A.1,B.1

int binarysearch(int a[],int left,int right,int key){
	if(left>right)
		return left;
	int mid=(left+right)/2;
	if(a[mid]==key)
		return mid;
	if(a[mid]<key)
		return binarysearch(a,mid+1,right,key);
	else
		return binarysearch(a,left,mid-1,key); 
}

int merge(int *a,int m,int *b,int n){
	int i;
	for(i=0;i<n;i++){
		int j=binarysearch(a,0,m-1,b[i]);
		int k=m;
		while(k>j){
			a[k]=a[k-1];
			k--;
		}
			
		a[j]=b[i];
		m++;
	}
	int maxtime=0,max=0;
	for(i=0;i<m-1;i++){
		int time=1;
		while((i<m-1)&&a[i]==a[i+1]){
			time++;
			i++;
		}
		if(time>maxtime){
			maxtime=time;
			max=a[i];
		}
	}
	return max;
}


int merge(int *a,int m,int *b,int n){
	int i;
	for(i=0;i<n;i++){
		int j=binarysearch(a,0,m-1,b[i]);//同上
		int k=m;
		while(k>j){
			a[k]=a[k-1];
			k--;
		}	
		a[j]=b[i];
		m++;
	}
	int count=0;
	for(i=0;i<m;i++){
		if(i+1<m&&a[i]==a[i+1])
			count++;
		else
			a[i-count]=a[i];
	}
	return m-count;
}

A.2

char minchar(char *a){
	char min=*a;
	char *ch=a++;
	while(*ch!='\0'){
		if(min>*ch)
			min=*ch;
		ch++;
	}
	return min;
}

A.3

int find(int n,int k){
	if(n==0&&k==0)
		return 1;
	if(k==0)
		return 2*find(n-1,k);
	if(k==n)
		return 3*find(n-1,k-1);
	return 2*find(n-1,k)+3*find(n-1,k-1);
} 

A.4,B.4

//1)
struct user{
	int ID;
	char type;
	char name[10];
	int date;
	struct user *next;
}; 

//2)
typedef struct user *LNode;

LNode create(){
	FILE *fp;
	if((fp=fopen("in.txt","r"))==NULL){
		printf("Open File Error!");
		return NULL; 
	}
	LNode p0=(LNode)malloc(sizeof(struct user));
	p0->next=NULL;
	while(!feof(fp)){
		LNode p=(LNode)malloc(sizeof(struct user));
		fscanf(fp,"%d%c",&p->ID,&p->type);
		fscanf(fp,"%s",p->name);
		fscanf(fp,"%d",&p->date);
		LNode pre=p0,rear=NULL;
		while(rear!=NULL&&rear->ID<p->ID){
			pre=rear;
			rear=rear->next;
		}
		pre->next=p;
		p->next=rear;
	}
    fclose(fp);
	return p0->next;
}

//3)
bool usercompare(LNode p1,LNode p2){
	if(p1->type>p2->type)
		return true;
	if(p1->type==p2->type&&p1->ID>p2->ID)
		return true;
	return false;
}

LNode sort(LNode head){
	if(head==NULL||head->next==NULL)
		return head;
	LNode p0=(LNode)malloc(sizeof(struct user));
	p0->next=head;
	LNode end=NULL;
	int flag;
	while(flag){
		LNode pre=p0;
		LNode p1=pre->next;
		LNode p2=p1->next;
		flag=0;
		while(p2!=end){
			if(usercompare(p1,p2)){
				pre->next=p2;
				p1->next=p2->next;
				p2->next=p1;
				flag=1;
				pre=p2;
			}
			else{
				pre=p1;
				p1=p2;
			}
			p2=p1->next;
		}
		end=p1;
	}
	head=p0->next;
	free(p0);
	return head;
}

 

//1,2同上
//3)
LNode reverse(LNode head){
	if(head==NULL||head->next==NULL)
		return head;
	LNode last=NULL;
	LNode p=head;
	while(p!=NULL){
		LNode rear=p->next;
		p->next=last;
		last=p;
		p=rear;
	} 
	return last;
}

B.2

int minpfac(int n){
	int i;
	for(i=2;i<=sqrt(n);i++)
		if(n%i==0)
			return i;
	return n;
}

B.3

int cut(int n,int k){
	if(n<=k)
		return 1;
	int n1=n*2/5;
	int n2=n-n1;
	return cut(n1)+cut(n2);
}

2015-唐班

A.1

void translate(int n){
	if(n==0)
		printf("0");
	else{
		int a[100];
		int len=0;
		while(n){
			a[len++]=n%2;
			n=n/2;
		}
		int i;
		for(i=len-1;i>=0;i--)
			printf("%d",a[i]);
	}
}

A.2

同2016-唐班 B.1

A.3

int f(int n){
	if(n==2)
		return 1;
	int i,sum=0;
	for(i=2;i<n;i++)
		sum+=(f(i)*f(n+1-i));
	return sum;
} 

A.4

//1) 
struct date{
	int y,m,d;
};

struct user{
	int ID;
	char name[10];
	struct date birth;
	struct user *next;
};

//2)
struct user *create(int k){
	FILE *fp;
	if((fp=fopen("in.txt","r"))==NULL){
		printf("Open File ERROR");
		return NULL;
	}
	struct user *head=(struct user*)malloc(sizeof(struct user));
	head->next=NULL;
	struct user *rear=head;
	int i;
	for(i=0;i<k;i++){
		struct user *p=(struct user*)malloc(sizeof(struct user));
		fscanf(fp,"%d%s%d%d%d",&p->ID,p->name,&p->birth.y,&p->birth.m,&p->birth.d);
		rear->next=p;
		rear=p;
	}
	rear->next=NULL;
	fclose(fp);
	return head->next;	 
}

//3)
struct user *insert(struct user *head){
	struct user *p=(struct user *)malloc(sizeof(struct user));
	scanf("%d%s%d%d%d",&p->ID,p->name,&p->birth.y,&p->birth.m,&p->birth.d);
	if(head==NULL)
		return p;
	if(p->ID<head->ID){
		p->next=head;
		return p; 
	}
	struct user *q=head,*pre=NULL;
	while(q!=NULL&&q->ID<p->ID){
		pre=q;
		q=q->next;
	}
	pre->next=p;
	p->next=q;
	return head;
} 

B.1

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

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	double hpi=1;
	int n=1;
	double temp=pow(n+1,2)/(n*(n+2));
	while(temp*hpi-hpi>=1e-5){
		hpi*=temp;
		n+=2;
		temp=(pow(n+1,2))/(n*(n+2));
	}
	printf("%lf",2*hpi); 
	return 0;
} 

B.2

int delarr(int a[],int n){
	int i,count=0;
	for(i=0;i<n;i++){
		if(a[i]%2==0)
			count++;
		else
			a[i-count]=a[i];
	}
	return n-count;
}

B.3

int f(int n){
	if(n==1)
		return 0;
	int i,result,min=f(n-1)+n-2;
	for(i=2;i<=n/2;i++){
		result=(n-i)-i+f(i)+f(n-i);
		if(result<min)
			min=result;
	}
	return min;
}

B.4


//1) 
struct date{
	int y,m,d;
};

struct user{
	int ID;
	char name[10];
	struct date birth;
	struct user *next;
};

//2)
struct user *deleteuser(struct user *head,int id){
	if(head==NULL)
		return NULL;
	struct user *rear=head;
	struct user *pre=NULL;
	while(rear!=NULL&&rear->ID!=id){
		pre=rear;
		rear=rear->next;
	} 
	if(rear==NULL){
		printf("未找到符合员工号的员工");
		return head;
	}
	if(rear==head){
		head=head->next;
		free(rear);
		return head;
	}
	pre->next=rear->next;
	free(rear);
	return head;
}

//3)
void output(int year,struct user *head){
	FILE *fp;
	if((fp=fopen("in.txt","r"))==NULL){
		printf("Open File ERROR");
		exit(0);
	}
	struct user *p=head; 
	while(p!=NULL){
		if(p->birth.y>year)
			fprintf(fp,"%d%s%d%d%d",p->ID,p->name,p->birth.y,p->birth.m,p->birth.d);
		p=p->next;
	} 
	fclose(fp);
} 

2014

A.1

bool isPrime(int n){
	if(n<2)
		return false;
	int i;
	for(i=2;i<=sqrt(n);i++){
		if(n%i==0)
			return false;
	}
	return true;
}

int delarr(int a[],int n){
	int i,count=0;
	for(i=0;i<n;i++){
		if(isPrime(a[i]))
			count++;
		else{
			printf("%d ",a[i]);
			a[i-count]=a[i];
		}	
	}
	return n-count;
} 

A.2 

int mystrlen(char *s){
	int len=0;
	while(s[len]!='\0')
		len++;
	return len;
} 

bool cmpstr(char *s){
	int len=mystrlen(s);
	int i,j;
	i=len/2;
	if(len%2==0)
		j=i+1;
	else
		j=i;
	while(i>=0&&j<=len-1){
		if(s[i]!=s[j])
			return false;
		i--;
		j++;
	}
	return true;
}

A.3 

float comp(float a[],int n){
	if(n==1)
		return a[0];
	return (a[n-1]+(n-1)*comp(a,n-1))/n;
}

A.4 

struct student{
	int ID;
	char name[10];
	int age;
	struct student *next;
};

struct student *create(int n){
	if(n==0)
		return NULL;
	struct student *p0=(struct student *)malloc(sizeof(struct student));
	struct student *rear=p0;
	int i;
	for(i=0;i<n;i++){
		struct student *p=(struct student*)malloc(sizeof(struct student));
		scanf("%d%s%d",&p->ID,p->name,&p->age);
		rear->next=p;
		rear=p;
	} 
	rear->next=NULL;
	struct student *head=p0->next;
	free(p0);
	return head;
}

A.5

struct student *agefilter(struct student *head){
	if(head==NULL)
		return head;
	FILE *fp;
	if((fp=fopen("out.txt","w"))==NULL){
		printf("Open File ERROR");
		exit(0);
	}
	int a;
	scanf("%d",&a);
	struct student *p0=(struct student*)malloc(sizeof(struct student));
	p0->next=head;
	struct student *pre=p0,*rear=head;
	while(rear!=NULL){
		if(rear->age==a){
			pre->next=rear->next;
			free(rear);
		}
		else{
			fprintf(fp,"%d%s%d\n",rear->ID,rear->name,rear->age);
			pre=rear;
		}
		rear=pre->next;
	}
	head=p0->next;
	free(p0);
	fclose(fp);
	return head;
}

B.1 

int delarr(int a[],int n){
	int i,count=0;
	for(i=0;i<n;i++){
		if(a[i]==0)
			count++;
		else{
			printf("%d ",a[i]);
			a[i-count]=a[i];
		}	
	}
	return n-count;
} 

B.2

int mystrlen(char *s){
	int len=0;
	while(s[len]!='\0')
		len++;
	return len;
} 

void sort(char *s){
	int len=mystrlen(s);
	int flag=1,end=len;
	while(flag){
		flag=0;
		int i;
		for(i=0;i<end;i++){
			if(i+1!=end&&s[i]>s[i+1]){
				char temp=s[i];
				s[i]=s[i+1];
				s[i+1]=temp;
				flag=1;
			}
		}
		end--;
	}
}

B.3

//k=(n/2)
int midnum(int a[],int n,int k){
	int i,min=0;
	for(i=1;i<n;i++){
		if(a[i]<a[min])
			min=i;
	}
	int temp=a[0];
	a[0]=a[min];
	a[min]=temp;
	if(k==1)
		return a[0];
	return (a+1,n-1,k-1);
}

B.4

struct teacher{
	int ID;
	char name[10];
	char sex;
	int year;
	struct teacher *next;
};

struct teacher *create(int n){
	if(n==0)
		return NULL;
	FILE *fp;
	if((fp=fopen("input.txt","r"))==NULL){
		printf("Open File ERROR");
		return NULL; 
	}
	struct teacher *p0=(struct teacher*)malloc(sizeof(struct teacher));
	p0->next=NULL;
	struct teacher *rear=p0;
	int i;
	for(i=0;i<n;i++){
		struct teacher *p=(struct teacher*)malloc(sizeof(struct teacher));
		fscanf(fp,"%d%s%c%d",&p->ID,p->name,&p->sex,&p->year);
		rear->next=p;
		rear=p;
	}
	rear->next=NULL;
	struct teacher *head=p0->next;
	free(p0);
	return head;
}

B.5 

struct teacher *yearfilter(struct teacher *head){
	if(head==NULL)
		return head;
	int y;
	scanf("%d",&y);
	struct teacher *p0=(struct teacher*)malloc(sizeof(struct teacher));
	p0->next=head;
	struct teacher *pre=p0,*rear=head;
	while(rear!=NULL){
		if(rear->year>y){
			pre->next=rear->next;
			free(rear);
		}
		else
			pre=rear;
		rear=pre->next;
	}
	head=p0->next;
	free(p0);
	return head;
}

2014-唐班

A.1

float comp(float a[][2],int n){
	if(n==0)
		return 0;
	else
		return a[n-1][0]*a[n-1][1]+comp(a,n-1);
}

A.2 

int changestr(char *s){
	int len=0;
	while(s[len]!='\0')
		len++;
	int i;
	for(i=0;i<len/2;i++)
		s[len-i-1]=s[i];
	return len;
}

A.3

bool isPrime(int n){
	if(n<2)
		return false;
	int i;
	for(i=2;i<=sqrt(n);i++){
		if(n%i==0)
			return false;
	}
	return true;
}

int delarr(int a[][10],int n){
	int i,j;
	int count=0;
	for(i=0;i<n;i++)
		for(j=0;j<10;j++){
			if(isPrime(a[i][j]))
				count++;
			else{
				int temp=(i+1)*(j+1)-count;
				if((temp-1)/n<n&&(temp-1)%10>=0)
					a[temp/n][(temp-1)%10]=a[i][j];
			} 
		}
	int num=(n*10-count);
	printf("最后一个有效元素:行:%d 列:%d",num/10,num%10);
	return num;
}

A.4

struct date{
	int y,m,d;
};

struct user{
	char ID[10];
	char name[10];
	struct date birth;
	struct user *next;
};

struct user *create(){
	struct user *p0=(struct user*)malloc(sizeof(struct user));
	p0->next=NULL;
	struct user *pre,*rear;
	printf("请输入职工的工号,姓名,出生年,月,日,工号输入四个0表示结束:\n");
	char id[10];
	scanf("%s",id);	
	while(strcmp(id,"0000")!=0){
		struct user *p=(struct user*)malloc(sizeof(struct user));
		strcpy(p->ID,id);
		scanf("%s%d%d%d",p->name,&p->birth.y,&p->birth.m,&p->birth.d);
		pre=p0,rear=pre->next;
		while(rear!=NULL&&rear->ID<p->ID){
			pre=rear;
			rear=rear->next;
		} 
		pre->next=p;
		p->next=rear;
		scanf("%s",id);	
	}
	struct user *head=p0->next;
	free(p0);
	return head;
}

A.5

void output(struct user *head){
	if(head=NULL);
		exit(0);
	FILE *fp;
	if((fp=fopen("output.dat","w"))==NULL){
		printf("Open File ERROR");
		exit(0);
	}
	struct user *p;
	while(p!=NULL){
		fprintf(fp,"%s %s %d年%d月%d日",p->ID,p->name,p->birth.y,p->birth.m,p->birth.d);
		p=p->next;
	}
	fclose(fp);
}

B.1

void output(char *s,char ch,int n){
	int len=strlen(s);
	int i=0,j=0;
	while(s[i]!=ch)
		i++;
	while(j<n){
		printf("%c",s[i+j]);
		j++;
	}	
}

B.2

int sum(int a[],int n){
	if(n==1)
		return a[0];
	return a[n-1]+sum(a,n-1);
}

B.3

int min_data(int *p,int n){
	if(n==1)
		return *p;
	return *(p+n-1)<min_data(p,n-1)?*(p+n-1):min_data(p,n-1);
}

B.4

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

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	printf("请输入学生的学号");
	int id,ID,score;
	scanf("%d",&id);
	FILE *fp;
	if((fp=fopen("source.txt","r"))==NULL)
		printf("文件不存在"); 
	else{
		while(!feof(fp)){
			fscanf(fp,"%6d%6d",&ID,&score);
			if(id==ID){
				printf("%6d%6d\n",ID,score);
				return 0;
			}	
		}
		printf("-1");
	}
	return 0;
} 


B.5

struct LNode{
	char data;
	struct LNode *next;
};

struct LNode *delnum(struct LNode *base){
	struct LNode *pre=base;
	struct LNode *rear=pre->next;
	while(rear!=NULL){
		if(rear->data>='0'&&rear->data<='9'){
			pre->next=rear->next;
			free(rear);
		}
		else
			pre=rear;
		rear=pre->next;
	}
	return base;
}

2013

A.1

void BubbleSort(int a[],int n){
	int flag=1,end=n;
	while(flag){
		flag=0;
		int i;
		for(i=0;i<end;i++){
			if(i+1<end&&a[i]>a[i+1]){
				int temp=a[i];
				a[i]=a[i+1];
				a[i+1]=temp;
				flag=1;
			}
		}
		end--;
	}
} 

A.2

int fac(int n){
	if(n==0)
		return 1;
	else
		return n*fac(n-1);
}

double fun(int n){
	if(n==1)
		return 0;
	else
		return (1.0*n/((n+1)*fac(n-2)))+fun(n-1);
}

A.3

double H(double x,int n){
	if(n==0)
		return 1;
	if(n==1)
		return 2*x;
	return 2*x*H(x,n-1)-2*(n-1)*H(x,n-2);
}

A.4

struct student{
	int ID;
	char name[10];
	int score;
	struct student *next;
};

struct student *create(){
	FILE *fp;
	if((fp=fopen("class531316.txt","r"))==NULL){
		printf("OPEN FILE ERROR");
		return NULL; 
	}
	struct student *p0=(struct student*)malloc(sizeof(struct student));
	p0->next=NULL;
	struct student *rear=p0;
	while(!feof(fp)){
		struct student *p=(struct student*)malloc(sizeof(struct student));
		fscanf(fp,"%d%s%d",&p->ID,p->name,&p->score);
		rear->next=p;
		rear=p;
	}
	rear->next=NULL;
	struct student *head=p0->next;
	free(p0);
	fclose(fp);
	return head;
}

A.5

struct LNode{
	int key;
	struct LNode *next;
};

struct LNode *del(struct LNode *head){
	if(head==NULL)
		return head;
	if(head->next==NULL){
		free(head);
		return NULL;
	}
	if(head->next->next==NULL){
		free(head->next);
		free(head);
		return NULL;
	}
	int max=head->key;
	int min=head->key;
	struct LNode *p=head->next;
	while(p!=NULL){
		if(p->key>max)
			max=p->key;
		if(p->key<min)
			min=p->key;
		p=p->next;
	}
	struct LNode *p0=(struct LNode*)malloc(sizeof(struct LNode));
	p0->next=head;
	struct LNode *pre;
	p=head;
	while(p!=NULL){
		if(p->key==max||p->key==min){
			pre->next=p->next;
			free(p);
		}
		else
			pre=p;
		p=pre->next;
	}
    return p0->next;
}

B.1

void fun(int a[],int n,int j){
	if(j>n)
		return ;
	while(n>0){
		a[n+j-1]=a[n-1];
		n--;
	}
	j--;
	while(j>=0){
		a[j--]=0;
	}
} 

B.2

int fac(int n){
	if(n==0)
		return 1;
	return n*fac(n-1);
}

double fun(int n){
	if(n<0)
		return 0;
	return 1.0*fac(n)/pow(2,n)+fun(n-1);
}

B.3

void fun(int n,int m){
	if(n<2)
		exit(0);
	int i;
	for(i=m;i<=n;i++){
		if(n%i==0){
			printf("%d ",i);
			fun(n/i,i);
		}	
	} 
}

B.4

struct student{
	int ID;
	char name[10];
	int score;
	struct student *next;
};

void output(struct student *head){
	FILE *fp;
	if((fp=fopen("class531316.txt","w"))==NULL){
		printf("OPEN FILE ERROR");
		exit(0);
	}
	struct student *p=head;
	int count=0;
	while(p!=NULL){
		if(p->score<60){
			fprintf(fp,"%d%s%d\n",p->ID,p->name,p->score);
			count++;
		}
		p=p->next;
	}
	fprintf(fp,"共%d位学生",count); 
	fclose(fp);
}

B.5

struct LNode{
	int key;
	struct LNode *next;
};

struct LNode *BubbleSort(struct LNode *head){
	int flag=1;
	struct LNode *end=NULL;
	struct LNode* p0=(struct LNode*)malloc(sizeof(struct LNode));
	p0->next=head;
	struct LNode *pre,*p,*rear;
	while(flag){
		flag=0;
		pre=p0;
		p=pre->next;
		rear=p->next;
		while(rear!=end){
			if(p->key>rear->key){
				pre->next=rear;
				p->next=rear->next;
				rear->next=p;
				flag=1;
				pre=rear;
			}
			else{
				pre=p;
				p=rear;
			}
			rear=rear->next;
		}
		end=p;
	}
	head=p0->next;
	free(p0);
	return head;
}

2012

A.1

int icount(int n){
	if(n<0)
		return -1; 
	if(n==0)
		return 0;
	return 1+icount(n/10);
} 

A.2

int del(int a[],int n){
	int count=0;
	int i;
	for(i=0;i<n;i++){
		if(i+1<n&&a[i]==a[i+1])
			count++;
		else
			a[i-count]=a[i];
	}
	return n-count;
} 

A.3

int gcd(x,y){
	if(x<y){
		int temp=x;
		x=y;
		y=temp;
	}
	if(y==0)
		return x;
	return gcd(y,x%y);
}

A.4

struct student{
	char name[10];
	bool sex;
	int score;
};


int create(struct student s[]){
	FILE *fp;
	if((fp=fopen("in.txt","r"))==NULL){
		printf("OPEN FILE ERROR");
		exit(0);
	}
	int i=0;
	while(!feof(fp)){
		fscanf(fp,"%s%d%d",s[i].name,&s[i].sex,&s[i].score);
		i++;
	}
	fclose(fp);
	return i;
}

A.5

struct LNode{
	int key;
	struct LNode *next;
};

struct LNode *del(struct LNode *head){
	if(head==NULL)
		return head;
	struct LNode *p0=(struct LNode*)malloc(sizeof(struct LNode));
	p0->next=head;
	struct LNode *pre;
	struct LNode *p=head;
	while(p!=NULL){
		if(p->key%2!=0){
			pre->next=p->next;
			free(p);
		}
		else
			pre=p;
		p=pre->next;
	}
	return p0->next;
}

B.1

int fun(int n){
	if(n>=0&&n<=9)
		return n;
	return fun(n/10);
} 

B.2

void sort(int a[],int n){
	int flag=1,end=n;
	while(flag){
		flag=0;
		int i;
		for(i=0;i<end;i++){
			if(i+1<end&&a[i]>a[i+1]){
				int temp=a[i];
				a[i]=a[i+1];
				a[i+1]=temp;
				flag=1;
			}
		}
		end--;
	}
}

void doublenum(int a[],int n){
	int k=2*n;
	int i;
	for(i=n;i<k;i++)
		a[i]=a[i-n];
	sort(a,k);
}

B.3

int digit(int n,int j){
	if(j==1)
		return n%10;
	return digit(n/10,j-1);
}

B.4

struct student{
	char name[10];
	bool sex;
	int score;
};

void output(struct student s[],int M){
	FILE *fp;
	if((fp=fopen("output.txt","w"))==NULL){
		printf("OPEN FILE ERROR!");
		exit(0);
	}
	int i,count=0;
	for(i=0;count<M;i++){
		if(s[i].score>=90){
			fprintf(fp,"%s %d %d",s[i].name,s[i].sex,s[i].score);
			count++;
		}
	}
	fclose(fp);
}

B.5

struct LNode{
	int data;
	struct LNode *next;
}; 

struct LNode *filter(struct LNode *head){
	struct LNode *p1=head;
	struct LNode *p2=p1->next;
	while(p1!=NULL&&p2!=NULL){
		if(p1->data>p2->data){
			p1->next=p2->next;
			free(p2);
			p1=p1->next;
		}
		else
			p1=p2;
		p2=p1->next;
	} 
	return head;
}

2011

A.1

bool isPrime(int n){
	int i;
	for(i=2;i<=sqrt(n);i++)
		if(n%i==0)
			return false;
	return true; 
}

bool f(int m,int n){
	if(!isPrime(m))
		return false;
	if(n%m!=0)
		return false;
	int i;
	for(i=m-1;i>=2;i--){
		if(n%i==0)
			return false;
	}
	return true;
}

A.2

void f(int a[],int n){
	int i=0,j=n-1;
	while(i<j){
		while(a[i]>0)
			i++;
		while(a[j]<=0)
			j--;
		if(i<j){
			int temp=a[i];
			a[i]=a[j];
			a[j]=temp;
		} 
	}
}

A.3,B.1

int fac(int n){
	if(n==0)
		return 1;
	return n*fac(n-1);
}
double f(int n){
	if(n==0)
		return 0;
	return (1.0*n)/((n+1)*fac(n+2))+f(n-1); 
}

A.4

struct student{
	char name[10];
	bool sex;
	int score;
};

void output(struct student s[],int n){
	FILE *fp;
	if((fp=fopen("output.txt","w"))==NULL){
		printf("OPEN FILE ERROR!");
		exit(0);
	}
	int i;
	for(i=0;i<n;i++)
		fprintf(fp,"%s %d %d",s[i].name,s[i].sex,s[i].score);
	fclose(fp);
}

A.5

struct LNode{
	int data;
	struct LNode *next;
}; 

struct LNode *filter(struct LNode *head,int x){
	struct LNode *p0=(struct LNode*)malloc(sizeof(struct LNode));
	p0->next=NULL;
	struct LNode *pre=p0;
	struct LNode *rear=pre->next;
	while(rear!=NULL){
		if(rear->data==x){
			pre->next=rear->next;
			free(rear);
			pre=pre->next;
		}
		else
			pre=rear;
		rear=pre->next;
	} 
	head=p0->next;
	free(p0);
	return head;
}

B.2

bool isexist(int a[],int n,int sum){
	if(n==0)
		return false; 
	if(a[0]==sum)
		return true;
	return isexist(a+1,n-1,a[0]+sum);
}

B.3

int f(int n){
	if(n==0)
		return 0;
	return (n%10)+f(n/10);
}

B.4

struct teacher{
	char name[10];
	bool sex;
	int age;
};

void input(struct teacher s[],int M){
	int i;
	for(i=0;i<M;i++)
		scanf("%s%d%d",s[i].name,&s[i].sex,&s[i].age);
}

B.5

struct teacher{
	char name[10];
	bool sex;
	int age;
	struct teacher *next;
};

void output(struct teacher *head){
	FILE *fp;
	if((fp=fopen("output.txt","w"))==NULL){
		printf("OPEN FILE ERROR");
		exit(0);
	}
	struct teacher *p=head;
	while(p!=NULL){
		if(!p->sex)
			fprintf(fp,"%s %d %d",p->name,p->sex,p->age);
		p=p->next;
	}
	fclose(fp);
}

2010

A.1

int minsum(int a[M][N],int m,int n){
	int min,sum=0;
	int i,j;
	for(i=0;i<m;i++,sum+=min)
		for(j=1,min=a[i][0];j<n;j++)
			if(a[i][j]<min)
				min=a[i][j];
	return sum;
} 

A.2

void mystrcpy(char *str1,int m,int n,char *str2){
	int k=strlen(str1);
	if(m+n>k)
		exit(0);
	int i,len=0;
	for(i=m;i<m+n;i++)
		str2[len++]=str1[i];
	str2[len]='\0';
}

A.3

int GCD(int m,int n){
	if(n==0)
		return m;
	return GCD(n,m%n);
}

A.4

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

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int key,temp;
	scanf("%d",&key);
	FILE *fp;
	if((fp=fopen("file.txt","r"))==NULL)
		printf("OPEN FILE ERROR");
	else{
		while(!feof(fp)){
			fscanf(fp,"%d",&temp);
			if(temp==key){
				printf("Y");
				break;
			}
		}
		if(feof(fp))
			printf("N");	 
	}
	fclose(fp);
	return 0;
} 


A.5

struct LNode{
	int data;
	struct LNode *next;
};

bool isPrime(int n){
	int i;
	for(i=2;i<=sqrt(n);i++)
		if(n%i==0)
			return false;
	return true;
}

void output(struct LNode *base){
	struct LNode *p=base->next;
	while(p!=NULL){
		if(isPrime(p->data))
			printf("%d ",p->data);
		p=p->next;
	}
}

B.1

int fun(int a[M][N],int m,int n,int *max,int *average){
	int i,j;
	*max=-9999;
	int sum=0;
	for(i=0;i<m;i++)
		for(j=0;j<n;j++){
			if(*max<a[i][j])
				*max=a[i][j];
			sum+=a[i][j];
		}
	*average=sum/(m*n); 
}

B.2

void fun(int a[][10],int N){
	int i,j;
	for(i=0;i<N;i++)
		for(j=0;j<N;j++)
			a[i][j]=0;
	for(i=0;i<N;i++)
		for(j=0;j<=i;j++)
			a[i][j]=(i+1)*(j+1);
}

B.3

int fac(int n){
	if(n==0)
		return 1;
	return n*fac(n-1);
}

int fun(int n){
	if(n==0)
		return 0;
	return fac(n%10)+fun(n/10);
}

B.4

int issymmetry(char *str){
	int len=strlen(str);
	int i,j;
	if(len%2==0){
		i=(len/2)-1;
		j=i+1;
	}
	else{
		i=(len/2)-1;
		j=i+2;
	}
	while(i>=0&&j<len){
		if(str[i]!=str[j])
			return 0;
		i--;
		j++; 
	}
	return 1;	
}

B.5

struct student{
	int ID;
	char name[10];
	char sex;
	int score;
	struct student *next;
};

struct student *CreatList(int n){
	struct student *p0=(struct student *)malloc(sizeof(struct student));
	p0->next=NULL;
	struct student *rear=p0;
	int i;
	for(i=0;i<n;i++){
		struct student *p=(struct student *)malloc(sizeof(struct student)); 
		scanf("%d",&p->ID);
		scanf(" %9s",p->name);
		scanf(" %c",&p->sex);
		scanf("%d",&p->score);
		rear->next=p;
		rear=p;
	}
	rear->next=NULL;
	return p0->next; 
}


void WriteFile(struct student *head){
	FILE *fp;
	if((fp=fopen("file.txt","w"))==NULL){
		printf("OPEN FILE ERROR");
		exit(0);
	}
	struct student *p=head;
	while(p!=NULL){
		fprintf(fp,"%d %s %c %d",p->ID,p->name,p->sex,p->score);
		p=p->next;
	}
	fclose(fp);
}

2009

A.1

int f(int n){
	if(n==1)
		return 0;
	if(n==2)
		return 1;
	return f(n-1)+f(n-2);
}

void fun(int n){
	int i;
	for(i=1;i<=n;i++)
		printf("%d ",f(i));
}

A.2

void yanghui(int a[N][N],int n){
	int i,j;
	a[1][1]=1;
	for(i=2;i<=n;i++)
		for(j=1;j<=i;j++)
			a[i][j]=a[i-1][j]+a[i-1][j-1];
}

int main(int argc, char *argv[]) {
	int a[N][N]={0};
	int n;
	scanf("%d",&n);
	yanghui(a,n);
	int i,j;
	for(i=1;i<=n;i++,printf("\n"))
		for(j=1;j<=i;j++)
			printf("%3d",a[i][j]);
	return 0;
} 

A.3

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
#define N 100

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int mystrlen(char *str){
	if(*str=='\0')
		return 0;
	return 1+mystrlen(str+1); 
} 

void mystrcpy(char *str1,char *str2){
	int len1;
	int len2=mystrlen(str2);
	for(len1=0;len1<len2;len1++)
		str1[len1]=str2[len1]; 
	str1[len1]='\0';
}

void fun(char *str1,char *str2){
	char temp[100];
	mystrcpy(temp,str1);
	mystrcpy(str1,str2);
	mystrcpy(str2,temp);
}

int main(int argc, char *argv[]) {
	char str1[100]="abc";
	char str2[100]="xyz";
	fun(str1,str2);
	puts(str1);
	puts(str2);
	return 0;
} 

A.4

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
#define N 100

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int min=101;
	int max=-1;
	int i,temp,sum=0;
	for(i=0;i<10;i++){
		scanf("%d",&temp);
		if(temp<min)
			min=temp;
		if(temp>max)
			max=temp;
		sum+=temp;
	}
	printf("%lf",1.0*(sum-min-max)/8);
	return 0;
} 

A.5

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
#define N 100

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

struct student{
	char name[10];
	long long num;
	struct student *next;
};

struct student *CreatList(int n){
	struct student *p0=(struct student*)malloc(sizeof(struct student));
	struct student *rear=p0;
	int i;
	for(i=0;i<n;i++){
		struct student *p=(struct student*)malloc(sizeof(struct student));
		scanf("%s%lld",p->name,&p->num);
		rear->next=p;
		rear=p;
	} 
	rear->next=NULL;
	return p0;
}

int main(int argc, char *argv[]) {
	struct student *head=CreatList(3);
	FILE *fp;
	if((fp=fopen("address.txt","w"))==NULL)
		printf("OPEN FILE ERROR");
	else{
		struct student *p=head->next;
		while(p!=NULL){
			fprintf(fp,"%s %lld\n",p->name,p->num);
			p=p->next;
		}
	} 
	fclose(fp);
	return 0;
} 


B.1

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
#define N 100

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

void mystrcpy(char *str1,char *str2){
	int len1;
	int len2=strlen(str2);
	int i=1;
	for(len1=0;i<len2;len1++){
		str1[len1]=str2[i];
		i+=2;
	}
	str1[len1]='\0';
}

int main(int argc, char *argv[]) {
	char str1[10],str2[10];
	gets(str1);
	mystrcpy(str2,str1);
	puts(str2);
	return 0;
} 


B.2

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
#define N 100

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

void fun(int a[],int len,int n,int b[][N]){
	int i,j;
	for(i=0;i<n;i++)
		for(j=0;j<n;j++){
			if(i+j<len)
				b[i][j]=a[i*n+j];
			else
				break;
		}		
}

int main(int argc, char *argv[]) {
	int a[100];
	int i;
	for(i=0;i<100;i++)
		a[i]=i+1;
	int n;
	scanf("%d",&n);
	int b[N][N]={0};
	fun(a,100,n,b);
	for(i=0;i<n;i++)
		printf("%d ",b[i][i]);
	return 0;
} 


B.3

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
#define N 100

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int GCD(int m,int n){
	if(m<n){
		int temp=m;
		m=n;
		n=temp;
	}
	if(n==0)
		return m;
	return (n,m%n);
}

int fun(int m,int n){
	return m*n/GCD(m,n);
}

int main(int argc, char *argv[]) {
	int x,y;
	scanf("%d%d",&x,&y);
	printf("%d",fun(x,y));
	return 0;
} 


B.4

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
#define N 100

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

struct student{
	char ID[9];
	char name[21];
	int score1;
	int score2;
	struct student *next;
};

struct student *CreatList(int n){
	struct student *p0=(struct student*)malloc(sizeof(struct student));
	struct student *rear=p0;
	int i;
	for(i=0;i<n;i++){
		struct student *p=(struct student*)malloc(sizeof(struct student));
		scanf("%8s",p->ID);
		scanf("%20s",p->name);
		scanf("%d",&p->score1);
		scanf("%d",&p->score2);
		rear->next=p;
		rear=p; 
	}
	rear->next=NULL;
	return p0; 
}

int main(int argc, char *argv[]) {
	struct student *head=CreatList(3);
	FILE *fp;
	if((fp=fopen("student.txt","w"))==NULL)
		printf("OPEN FILE ERROR");
	else{
		struct student *p=head->next;
		while(p!=NULL){
			fprintf(fp,"%s %s %d %d \n",p->ID,p->name,p->score1,p->score2);
			p=p->next;
		}
	} 
	fclose(fp);
	return 0;
} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值