这个程序是为了找到给定输入的集合。即删除重复的元素。 [英] this program is meant to find the set out of the given input.i.e remove the repeated elements.

查看:66
本文介绍了这个程序是为了找到给定输入的集合。即删除重复的元素。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< stdio.h>

int count;

void create(float seta [],int n1,float tempa []);

int main()

{int i;

float * seta; float * setb; float * tempa; int n1,n2;

printf(输入集合1的元素:\ n);

printf(输入集合1中的元素数量:\\ n \\ n);

scanf(%d,& n1);

seta =(float *)malloc(n1 * sizeof(float));

for(i = 0; i< n1; i ++)

{

scanf(%f,seta + i);





}



printf(输入第2集的元素:\\ \\ n);

printf(输入第2组中的元素数量:\ n);

scanf(%d,& n2) ;

setb =(float *)malloc(n2 * sizeof(float));

for(i = 0; i< n2; i ++)

{

scanf(%f,setb + i);





}

create(seta,n1,tempa);

for(i = 0; i< count; i ++)

printf(%d ,*(tempa + i));





返回0;

}

void create(float a [20],int n1,float tempa [20])

{int count = 1,i,j,countverify; a [0] = tempa [0] ;

for(i = 0; i< n1; i ++)

{countverify = 0; for(j = 0; j< count; j ++)

if(tempa [j]!= a [i]){countverify ++;}

if(countverify ==数)

{

tempa [count] = a [i];计数++; }

}





} / *如果你想要,可以删除set b。声明要在后期阶段设置opwrations但首先让我知道错误是什么。我的编译器在扫描元素后停止了* /

#include<stdio.h>
int count;
void create(float seta[],int n1,float tempa[] );
int main()
{ int i;
float *seta; float *setb; float *tempa; int n1,n2;
printf("enter the elements of set 1:\n");
printf("enter the number of elements in set 1:\n");
scanf("%d",&n1);
seta=(float*)malloc(n1*sizeof(float));
for(i=0;i<n1;i++)
{
scanf("%f",seta+i);


}

printf("enter the elements of set 2:\n");
printf("enter the number of elements in set 2:\n");
scanf("%d",&n2);
setb=(float*)malloc(n2*sizeof(float));
for(i=0;i<n2;i++)
{
scanf("%f",setb+i);


}
create(seta,n1,tempa);
for(i=0;i<count;i++)
printf("%d",*(tempa+i));


return 0;
}
void create(float a[20],int n1,float tempa[20])
{int count=1,i,j,countverify;a[0]=tempa[0];
for(i=0;i<n1;i++)
{countverify=0; for(j=0;j<count;j++)
if(tempa[j]!=a[i]) {countverify++;}
if(countverify==count)
{
tempa[count]=a[i]; count++; }
}


} /*the set b can be removed if you want.it has been declared to do furthur set opwrations at later stages but first let me know what the error is .my compiler stopped after scanning the elements*/

推荐答案

你malloc seta setb - 但你不要为tempa分配任何东西



并且它不是你的编译器停止 - 编译器只是将你的C代码转换为可执行的应用程序。一旦完成,您的应用程序就是自己的;编译器没有进一步涉及。

而不是仅仅编译器在...后停止,使用调试器。设置一个断点并按照代码查看确切的结果。这是一项技能,当你还在为小项目工作时,这是非常值得开发的。



和顺便说一句:释放你所有内存的好习惯,即使你要退出该计划。如果你养成这种习惯,你就不会在更复杂的项目中开始出现可怕的内存泄漏问题。
You malloc seta and setb - but you don;t allocate anything to tempa

And it's not "your compiler" that stopped - the compiler just converts your C code into an executable application. Once that's complete, your app is on it's own; the compiler in not involved any further.
Instead of just going "the compiler stopped after...", use the debugger. Set a break point and follow the code through to find out exactly what is happening. It's a skill, and it';s well worth developing when you are still working on small projects.

And BTW: it's good practice to free all memory you malloc, even if you are going to exit the program. If you get into the habit, you don't start getting horrible memory leak problem in more complex projects.


这篇关于这个程序是为了找到给定输入的集合。即删除重复的元素。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆