求集合A与集合B的关系 有什么错误?#include #include int IsIncluded ( int *A,int a,int *B,int b);void main(){\x05int c;\x05int *A,i,N;\x05int *B,H;\x05printf("please input A length:" );\x05\x05scanf("%d",&N);\x05A = (int *) malloc(N * size

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/27 00:32:53
求集合A与集合B的关系 有什么错误?#include #include int IsIncluded ( int *A,int a,int *B,int b);void main(){\x05int c;\x05int *A,i,N;\x05int *B,H;\x05printf(

求集合A与集合B的关系 有什么错误?#include #include int IsIncluded ( int *A,int a,int *B,int b);void main(){\x05int c;\x05int *A,i,N;\x05int *B,H;\x05printf("please input A length:" );\x05\x05scanf("%d",&N);\x05A = (int *) malloc(N * size
求集合A与集合B的关系 有什么错误?
#include
#include
int IsIncluded ( int *A,int a,int *B,int b);
void main()
{\x05int c;
\x05int *A,i,N;
\x05int *B,H;
\x05printf("please input A length:" );
\x05\x05scanf("%d",&N);
\x05A = (int *) malloc(N * sizeof(int));
\x05for( i=0;i

求集合A与集合B的关系 有什么错误?#include #include int IsIncluded ( int *A,int a,int *B,int b);void main(){\x05int c;\x05int *A,i,N;\x05int *B,H;\x05printf("please input A length:" );\x05\x05scanf("%d",&N);\x05A = (int *) malloc(N * size
你的程序没有多大问题,但是你的程序中比较集合的时候是不需要break的,你的问题出在free B 的时候指针越界.我没注意你B的问题
先修改如下:
#include <stdio.h>
#include <stdlib.h>
int IsIncluded ( int *A,int a,int *B, int b);
void  main()
{\x05int c;
\x05int *A,i,N;
\x05int *B,H;
\x05printf("please input A length: " );
\x05\x05scanf("%d", &N);
\x05A = (int *) malloc(N * sizeof(int));
\x05for( i=0;i<N;i++)
\x05\x05scanf("%d",&A[i]);

\x05printf("\nplease input B length: " );
\x05\x05scanf("%d", &H);
\x05B = (int *) malloc(N * sizeof(int));
\x05
\x05for( i=0;i<H;i++)
\x05\x05scanf("%d",&B[i]);
\x05c=IsIncluded ( A,N,B,H);
\x05
\x05if (c==1)
\x05\x05printf ( " \n  A 包含于 B\n" )  ;
\x05else 
\x05\x05printf ( " \n  A 不包含于 B\n" )  ;

\x05//free (A);
\x05//free (B);
\x05
}

int IsIncluded ( int *A,int a,int *B, int b)
{
\x05int i,j;
\x05int count =0;
\x05if(a>b)
\x05\x05return 0;
\x05for (i=0;i<a;i++)
\x05{ 
\x05\x05for (j=0;j<b;j++)
\x05\x05{
\x05\x05\x05if (\x05*(A +i) ==*(B+j))
\x05\x05\x05\x05count++; //break;
\x05\x05\x05
\x05\x05}
\x05}
\x05if (count ==a)
\x05\x05return 1;
\x05else 
\x05\x05return 0;
\x05
}