Logo 
Search:

C++ Programming Forum

Ask Question   UnAnswered
Home » Forum » C++ Programming       RSS Feeds

help: Difference between two arrays

  Asked By: Geac    Date: Mar 01    Category: C++ Programming    Views: 3008
  

Hello comunity,

I have to make a program which takes input two arrays (a and b) and outputs (c, c=a-b, c will containt the elements from a which are not in b).

Also each element in a and b must not repeat.

I started the sketch the code, but I'm so tired and the compiler was harsh with me, the main ideea is good I think.
What I seek is help.
If this is not a good solution then please help me find one.
Why does it give so manny errors, why is vc++ 2010 compiler so nasty, in borland when I clicked the error it pointed me to the line with the problem, can vc++ do the same?

Also it has to be modular.
Here is the code:


code.h

#ifndef code_h
#define code_h

void readArr(int,int);
void writeArr(int,int):
void difference(int,int,int,int,int);

#endif




code.cpp

#include "code.h"
#include <iostream>
using namespace std;

void readArr(int a[50],int n)
{ int i;
cout<<"size:"<<n<<endl;
cout<<"insert the elements";
for( i=1;i<=n;i++)
cout<<"a["<<i<<"]=";
cin>>a[i];

if(a[i]==a[i+1])//verify if two numbers repeat
a[i]=a[i+1];
}

void writeArr(int a[50], int n)
{
int i;
cout<<endl;
cout<<"the elements are:"<<endl;
for( i=1;i<=n;i++)
cout<<a[i]<<" ";
}

void difference(int a[50],int n,int b[50],int m, int c[50])
{
int i=0;
int j=0;
int k=0;
while((i<=n) && (j<=m))
{
if(a[i]!=b[j])
c[k]=a[i];
i++; j++; k++;
}
}



main.cpp

#include <iostream>
#include "code.h"
#include <conio.h>

using namespace std;

int main()
{
int a[50],b[50],c[50],n,m;
cout<<"a"; readArr(a,n);
cout<<"b"; readArr(b,m);
difference(a,b,c);
cout<<"elements of c are:"<<endl;
writeArr(c,n);
_getch();
return 0;
}

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Geac Papatel     Answered On: Mar 02

Ignore all I wrote, gibberish.

 
Didn't find what you were looking for? Find more on help: Difference between two arrays Or get search suggestion and latest updates.




Tagged: