一、 PTA作业。
在完成PTA作业的时候我没有认真读题。每次都是提交完整代码
6-1(1)
1 #include2 3 //P++等价于(p)++还是等价于*(p++)? 4 5 int main(){ 6 int *p, a = 3; 7 p = &a; 8 printf("*p = %d ",*p); 9 printf("p = %d ",p); 10 printf("p++ = %d ",p++); 11 printf("(p)++ = %d ",(p)++); 12 printf("*p++ = %d ",*p++); 13 printf("*(p++) = %d ",*(p++)); 14 }
6-2(1)
void splitfloat( float x, int *intpart, float *fracpart ){*intpart = x / 1;*fracpart = x - *intpart; }
6-1(2)
int search(int list[], int n, int x){int i;for(i = 0;i){if(x == list[i]){return i;}}return -1; }
6-2(2)
int fun(int *a, int *b, int n){ int *c,max=*a;for(c=a+1;c)if(*c>max) {max=*c;*b=(c-a);}return max; }
6-1(3)
void input(int *arr, int n){int i;for(i = 0; i < 10; i++){scanf("%d",&*(arr+i));} }void max_min(int *arr,int n){ int mark=0,flag=0;int j=0;int c1,c2;int max=*arr,min=*arr;for(j=0;j<10;j++){ if(*(arr+j)>max){max=*(arr+j);mark=j;}if(*(arr+j)<min){min=*(arr+j);flag=j;}}c1=*arr;*(arr)=min;*(arr+flag)=c1;c2=*(arr+9);*(arr+9)=max;*(arr+mark)=c2; } void output(int *arr,int n){int k=0;for(k=0;k<10;k++){printf("%3d",*(arr+k));} }
6-2(3)
void sort(int *x, int n){int i, j, k, mark, c1, max;for(i = 0; i<10; i++){max = *(x+i);for(j=i; j<10; j++){if(*(x+j)>max){max = *(x+j);mark = j;}}c1 = *(x+i);*(x+i) = *(x+mark);*(x+mark) = c1;} }
6-1(4)
bool palindrome( char *s ){int i=0,j=0,answer=1;char *b = s;for(;*b != '