571255
An1006216251
200922226
An52385712515-3读取文件内容
#include"stdio.h"
main()
{ FILE *fp;
int m,n,i=0;
char file[20],ch[20],c;
scanf("%s%d",file,&n);
if( ( fp=fopen(file,"r") )==NULL)
{ printf("File Name Error.\n");
exit(0);
}
if(n>5)
printf("Line No Error.\n");
if(n==1)
printf("T");
for(i=1;(c=fgetc(fp))!=EOF;)
{
if(c=='\n')
i++;
for(;i==n;)
{ c=fgetc(fp);
putchar(c);
if(c=='\n')
{ i++;
break;
}
}
}
fclose(fp);
}
15-2数据编号
void sort ( struct data *pa , int n )
{ int i,j,k=0;
for(i=0;i
{ while(pa[k].no!=0)
k++;
for(j=0;j
if(pa[j].no==0&&*pa[j].p
k=j;
pa[k].no=i+1;
}
}
15-1输出字母正方形
#include"stdio.h"
main()
{ int i,n,j,k,m,l;
char a,min();
scanf("%c %d",&a,&n);
if(96
a=a-32;
k=a;
m=(n+1)/2;
for(i=0;i
{ for(j=0;j
if(j
printf("%c",min(a,i,j));
else
if(j>=m&&i
printf("%c",min(a,i,n-j-1));
else
if(j=m)
printf("%c",min(a,n-i-1,j));
else
printf("%c",min(a,n-i-1,n-1-j));
printf("\n");
}
}
char min( char a,int i,int j )
{ char k;
if(i<=j)
k=i+a;
else
k=j+a;
if(k>90)
k=k-26;
return(k);
}
14-3数制转换
#include"stdio.h"
#include"string.h"
main()
{ int m,n,i,j,k;
char a[10][10]={'\0'};
scanf("%d%d",&n,&m);
for(k=0;;k++)
{ scanf("%s",&a[k]);
if(strcmp(a[k],"0")==0)
break;
}
for(i=0;i
{daoshu ( a[i] );
j=shi( a[i] , n );
zhuanm(j,m);
if(i
printf(" ");
}
printf("\n");
}
shi( char *p ,int n )
{ int j;
if(*(p+1)=='\0')
j=(*p-48);
else
j=(*p-48)+n*shi( p+1,n );
return(j);
}
zhuanm(int j,int m)
{
if(j
printf("%d",j);
else
{ zhuanm( j/m,m );
printf("%d",j%m);
}
}
daoshu( char *a )
{ char *p=a,temp;
while( *p!='\0')
p++;
p--;
while(a
{ temp=*a;
*a=*p;
*p