Aswin - 11 months ago 59

C Question

This is my program but doesn't work as it is incomplete.

`using namespace std;`

int main(){

int a[]={101,102,103,104,107,110};

int n = sizeof(a) / sizeof(int);

int b[]={102,103,101};

int m = sizeof(b) / sizeof(int);

int c[20];

static int k=0;

int flag;

for(int j=0;j<m;j++)

{

if(a[0]!=b[j])

{

c[k]=b[j];

printf("c[%d]=%d\n",k,c[k]);

k++;

}

}

return 0;

}

I need to find the C Array which contains unsold items.

I tried several hours trying to find a solution, but I cannot come up with any thing simple. Would be great if someone helps.

Answer Source

I think you like to find this:

```
#include <iostream>
using namespace std;
int main(){
int a[]={101,102,103,104,107,110};
int n = sizeof(a) / sizeof(int);
int b[]={102,103,101};
int m = sizeof(b) / sizeof(int);
int c[20];
static int k=0;
int flag;
for(int i =0;i<n;i++){
int f=0;
for(int j=0;j<m;j++)
{
if(a[i]==b[j])
{
f=1;
}
}
if(f==0)
{
c[k]=a[i];
printf("c[%d]=%d\n",k,c[k]);
k++;
}
}
return 0;
}
```

**OUTPUT**

```
c[0]=104
c[1]=107
c[2]=110
```