p1++; p2++; } *p2='\\0'; } 8-8
#include
{int upper=0,lower=0,digit=0,space=0,other=0,i=0; char *p,s[20];
printf(\ \
while ((s[i]=getchar())!='\\n') i++; p=&s[0];
while (*p!='\\n')
{if (('A'<=*p) && (*p<='Z')) ++upper;
else if (('a'<=*p) && (*p<='z')) ++lower; else if (*p==' ') ++space;
else if ((*p<='9') && (*p>='0')) ++digit; else
++other; p++; }
printf(\ lower case:%d\
printf(\ space:%d digit:%d other:%d\\n\return 0; } 8-9
#include
{void move(int *pointer); int a[3][3],*p,i;
printf(\ for (i=0;i<3;i++)
scanf(\ p=&a[0][0]; move(p);
printf(\ for (i=0;i<3;i++)
printf(\ return 0;
}
void move(int *pointer) {int i,j,t;
for (i=0;i<3;i++) for (j=i;j<3;j++)
{t=*(pointer+3*i+j);
*(pointer+3*i+j)=*(pointer+3*j+i); *(pointer+3*j+i)=t; } } 8-10-2
#include
{void change(int *p); int a[5][5],*p,i,j;
printf(\ for (i=0;i<5;i++) for (j=0;j<5;j++)
scanf(\ p=&a[0][0]; change(p);
printf(\ for (i=0;i<5;i++) {for (j=0;j<5;j++)
printf(\ printf(\ }
return 0; }
void change(int *p) // {int i,j,temp;
int *pmax,*pmin; pmax=p; pmin=p;
for (i=0;i<5;i++) //ֵСֵĵַ, pmax,pmin for (j=i;j<5;j++)
{if (*pmax<*(p+5*i+j)) pmax=p+5*i+j; if (*pmin>*(p+5*i+j)) pmin=p+5*i+j; }
temp=*(p+12); //ֵԪػ *(p+12)=*pmax; *pmax=temp;
temp=*p; //СֵϽԪػ *p=*pmin; *pmin=temp;
pmin=p+1;
//a[0][1]ĵַpminӸλÿʼСԪ for (i=0;i<5;i++) //ҵڶСֵĵַ pmin for (j=0;j<5;j++) {if(i==0 && j==0) continue;
if (*pmin > *(p+5*i+j)) pmin=p+5*i+j; }
temp=*pmin; //ڶСֵϽԪػ *pmin=*(p+4); *(p+4)=temp;
pmin=p+1;
for (i=0;i<5;i++) //ҵСֵĵַpmin for (j=0;j<5;j++) {if((i==0 && j==0) ||(i==0 && j==4)) continue; if(*pmin>*(p+5*i+j)) pmin=p+5*i+j; }
temp=*pmin; // Сֵ½Ԫػ *pmin=*(p+20); *(p+20)=temp;
pmin=p+1;
for (i=0;i<5;i++) // ҵСֵĵַpmin for (j=0;j<5;j++) {if ((i==0 && j==0) ||(i==0 && j==4)||(i==4 && j==0)) continue; if (*pmin>*(p+5*i+j)) pmin=p+5*i+j; }
temp=*pmin; //Сֵ½Ԫػ *pmin=*(p+24); *(p+24)=temp; } 8-11-1
#include
{void sort(char s[][6]); int i;
char str[10][6];
printf(\ for (i=0;i<10;i++)
scanf(\ sort(str);
printf(\ for (i=0;i<10;i++) printf(\ return 0; }
void sort(char s[10][6]) {int i,j;
char *p,temp[10]; p=temp;
for (i=0;i<9;i++) for (j=0;j<9-i;j++)
if (strcmp(s[j],s[j+1])>0) {strcpy(p,s[j]);
strcpy(s[j],s[+j+1]); strcpy(s[j+1],p); } } 8-12
#include
{void sort(char *[]); int i;
char *p[10],str[10][20]; for (i=0;i<10;i++) p[i]=str[i];
printf(\ for (i=0;i<10;i++) scanf(\ sort(p);
printf(\ for (i=0;i<10;i++) printf(\ return 0; }
void sort(char *s[]) {int i,j;
char *temp; for (i=0;i<9;i++) for (j=0;j<9-i;j++)