+ 1

Display all these arrays at the end of the program.

Question is this: Write a c++ program that stores 20 numbers in two arrays A and B ie 10 numbers in each array. Declare another array C.Now, compare the elements of the two arrays A and B , and put all the numbers that do not have a duplicate, into the array C. Display all these arrays at the end of the program.

16th Oct 2018, 10:42 AM
Suresh Thiyam
Suresh Thiyam - avatar
5 Respuestas
+ 1
#include<iostream> using namespace std; int main(){     int a[10],b[10],c[20],i,j;     cout<<"Enter 10 numbers for A"<<endl;     for(i=0;i<10;i++){         cin>>a[i];     }     cout<<"Enter 10 numbers for B"<<endl;     for(j=0;j<10;j++)     {         cin>>b[j];     }      for(int i=0;i<10;i++){             for(int j=0;j<10;j++)             {                if(a[i]!=b[j]){             c[i]=a[i];         }         cout<<c[i];             }      }     return 0; }
16th Oct 2018, 10:43 AM
Suresh Thiyam
Suresh Thiyam - avatar
+ 1
I tried this code , I think the output is wrong, please correct me
16th Oct 2018, 10:44 AM
Suresh Thiyam
Suresh Thiyam - avatar
+ 1
I dont think that you have to compare only items to same index of a and b for find a duplicated... Example: a= [1,2,3] b= [5,1,1] c would be: c= [2,3,5] because duplicated cannot appear in same array and in different indices... I have right? P.S. Save always code longer than 6-7 lines in 'Code Playground' section and post here his link... In this way we can help you better (without copy, reformat and execute all)
16th Oct 2018, 11:59 AM
KrOW
KrOW - avatar
+ 1
so, what would be the correct code? I'm confused here
16th Oct 2018, 12:16 PM
Suresh Thiyam
Suresh Thiyam - avatar
0
Suresh Thiyam Try to figure out yourself... You know that you have to compare ALL items in EITHER arrays (a and b). Then, how you can do this? Hint: Think of either arrays like a single array Futhermore you have think how you program have to handle c array... If all 20 items are different, no problem but what if there are duplicated items? Hint: Here you have to use something for "signal" how many items of c are useful for you problem
16th Oct 2018, 12:33 PM
KrOW
KrOW - avatar