指针的指针,传递数组的地址,应该用什么变量接受?
程序代码:
#include<stdio.h> typedef struct MultiNomial { char data; int coef; int power; }MultiNo; int NA,NB; void Sort(MultiNo A[],int N) { int i,j; int sign = 1; for(i = 1; i<N && sign; i++) { sign = 0; for(j = N-1; j>=i; j--) { if(A[j].power < A[j+1].power) { A[0] = A[j]; A[j] = A[j+1]; A[j+1] = A[0]; sign = 1; } } } } void Print(MultiNo *A,int N) { int i; i = 1; while(i<=N) { if(A[i].coef > 0) printf("+%d%c%d",A[i].coef,A[i].data,A[i].power); else printf("%d%c%d",A[i].coef,A[i].data,A[i].power); i++; } putchar('\n'); } void Creat(MultiNo *A,int *N) { int i; printf("please input N mutilnomials and N<50:\n"); scanf("%d",&(*N)); for(i=1; i<=(*N); i++) { printf("please input the %d datas as 3,x,2: ",i); fflush(stdin); scanf("%d,%c,%d",&(A[i].coef),&(A[i].data),&(A[i].power)); } } void Add(MultiNo **A,MultiNo B[]) { int i,j,k; MultiNo C[50]; i = j = k = 1; while(i<=NA && j<=NB) { if((*A[i]).power > B[j].power) C[k++] = *A[i++]; else if((*A[i]).power < B[j].power) C[k++] = B[j++]; else { (*A[i++]).coef += B[j++].coef; C[k++] = *A[i]; } } while(i<=NA) C[k++] = *A[i++]; while(j<=NB) C[k++] = B[j++]; k--; for(i=1,j = 1; i<=k; i++) { if(C[i].coef != 0) *A[j++] = C[i]; } NA = j-1; } void Sub(MultiNo *A,MultiNo B[]) { int i,j,k; MultiNo C[50]; i = j = k = 1; for(;i<=NA && j<=NB;) { if(A[i].power > B[j].power) C[k++] = A[i++]; else if(A[i].power < B[j].power) { B[j].coef = -B[j].coef; C[k++] = B[j++]; } else { A[i].coef -= B[j++].coef; C[k++] = A[i++]; } } while(i<=NA) C[k++] = A[i++]; while(j<=NB) { B[j].coef = -B[j].coef; C[k++] = B[j++]; } k--; for(i=1,j = 1; i<=k; i++) { if(C[i].coef != 0) { A[j++] = C[i]; printf("%d%c%d ",C[i].coef,C[i].data,C[i].power); } } NA = j-1; } void main() { MultiNo A[50],B[50]; int i,j; char operation; Creat(A,&NA); Creat(B,&NB); Sort(A,NA); Sort(B,NB); fflush(stdin); printf("enter + to add the two multinomial:\nenter - to subtract the two multinomial:\n"); scanf("%c",&operation); switch(operation) { case '+':Add(A,B);break; case '-':Sub(A,B);break; default :puts("wrong choice");break; } Print(A,NA); getch(); }