c语言题目,求大神解答

尽量用简单的程序,谢谢啦... 尽量用简单的程序,谢谢啦 展开
 我来答
White_MouseYBZ
2019-01-07 · TA获得超过4万个赞
知道大有可为答主
回答量:2.1万
采纳率:82%
帮助的人:6281万
展开全部

1)

#include "stdio.h"
#include <string.h>
void mysort(char (*p)[50],int n){
int i,j,k;
char t[50];
for(i=0;i<n;i++){
for(k=i,j=k+1;j<n;j++)
if(strcmp(p[k],p[j])>0)
k=j;
if(k!=i){
for(j=0;t[j]=p[i][j];j++);
for(j=0;p[i][j]=p[k][j];j++);
for(j=0;p[k][j]=t[j];j++);
}
}
}
int main(int argc,char *argv[]){
char s[100][50],n,i;
FILE *fp,*fpo;
fp=fopen("d:\\books.txt","r");
if((fpo=fopen("d:\\books_sorted.txt","w"))==NULL){
printf("Open the file failure...\n");
return 0;
}
for(n=0;fscanf(fp,"%s",s[n])!=EOF;n++);
fclose(fp);
mysort(s,n);
for(i=0;i<n;fprintf(fpo,"%s\n",s[i++]));
fclose(fpo);
return 0;
}

运行样例:

2)

#include "stdio.h"
struct stu{
char name[21];
int by,bm,bd;
};
int myfind(struct stu *p){
int m[]={31,28,31,30,31,30,31,31,30,31,30,31};
m[1]+=p->by%4==0 && p->by%100 || p->by%400==0;
return p->bm>0 && p->bm<13 && p->bd>0 && p->bd<=m[p->bm-1];
}
int main(int argc,char *argv[]){
struct stu stu;
FILE *fp;
if((fp=fopen("d:\\students.txt","r"))==NULL){
printf("Open the file failure...\n");
return 0;
}
printf("Invalid date as follows:\n");
while(fscanf(fp,"%s%d-%d-%d",stu.name,&stu.by,&stu.bm,&stu.bd)!=EOF)
if(!myfind(&stu))
printf("%s %d-%d-%d\n",stu.name,stu.by,stu.bm,stu.bd);
fclose(fp);
return 0;
}

运行样例:

3)

#include "stdio.h"
int main(int argc,char *argv[]){
int n,g,l,f,s,t;
FILE *fp;
if((fp=fopen("d:\\scores.txt","r"))==NULL){
printf("Open the file failure...\n");
return 0;
}
for(g=-1,l=101,f=n=s=0;fscanf(fp,"%d",&t)!=EOF;n++){
if(g<t)
g=t;
if(l>t)
l=t;
if(t<60)
f++;
s+=t;
}
printf("The total number of %d people.\n",n);
printf("The highest: %d\nThe lowest: %d\nThe average: %.2f\n",g,l,s/(n+0.0));
printf("%d people didn't pass the exam.\n",f);
  return 0;
}

运行样例:

4)

#include "stdio.h"
int myfunc(int n){
int m,t;
for(t=n,m=0;t;t/=10)
(m*=10)+=t%10;
return m==n;
}
int main(int argc,char *argv[]){
int n,k=0;
FILE *fp;
if((fp=fopen("d:\\numbers.txt","r"))==NULL){
printf("Open the file failure...\n");
return 0;
}
while(fscanf(fp,"%d",&n)!=EOF){
if(myfunc(n))
printf(++k%5 ? "%11d" : "%11d\n",n);
}
fclose(fp);
if(k%5)
printf("\n");
  return 0;
}

运行样例:

本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式