I have three C functions that work perfectly but I am not allowed to use continue, break to get out of loop. I need help in modfying the function so it will give the same output without the inclusion of continue(highlighted in bold) int setIntersection(String *A, String *B, String *C, int nElemA, int nElemB){ //Set the nElemc to zero int nElemC = 0; //Set the for loop over A for(int i = 0 ; i< nElemA ; i++){ //Set the for loop over the B for(int j = 0 ; j< nElemB ; j++){ //Check if element already present in both if(strcmp(A[i],B[j]) == 0){ //Then add the element in the c strcpy(C[nElemC], A[i]); //Increment the nEleC nElemC++; //Break after the match continue;; } } } //Print the intersection for(int i = 0; i < nElemC; i++) printf("%s ", C[i]); return nElemC; } //For the difference int setDifference(String *A, String *B, String *C, int nElemA, int nElemB){ //Set the nElemc to zero int nElemC = 0; //We have to remove the set B from the set A. //Iterate over the A for(int i = 0 ; i
I have three C functions that work perfectly but I am not allowed to use continue, break to get out of loop. I need help in modfying the function so it will give the same output without the inclusion of continue(highlighted in bold)
int setIntersection(String *A, String *B, String *C, int nElemA, int nElemB){
//Set the nElemc to zero
int nElemC = 0;
//Set the for loop over A
for(int i = 0 ; i< nElemA ; i++){
//Set the for loop over the B
for(int j = 0 ; j< nElemB ; j++){
//Check if element already present in both
if(strcmp(A[i],B[j]) == 0){
//Then add the element in the c
strcpy(C[nElemC], A[i]);
//Increment the nEleC
nElemC++;
//Break after the match
continue;;
}
}
}
//Print the intersection
for(int i = 0; i < nElemC; i++)
printf("%s ", C[i]);
return nElemC;
}
//For the difference
int setDifference(String *A, String *B, String *C, int nElemA, int nElemB){
//Set the nElemc to zero
int nElemC = 0;
//We have to remove the set B from the set A.
//Iterate over the A
for(int i = 0 ; i<nElemA ; i++){
//Set ele found to 1 in case the element from b is found in a
int EleFound = 0;
//Now iterate over the B
for(int j = 0 ; j < nElemB ; j++){
if(strcmp(A[i],B[j]) == 0){
//Set elefound to 1 in case the element from b is present in a
EleFound = 1;
//Get out of the loop
continue;
}
}
//Check if Elefound is 0 . If yes then add the element in differnce else ignore it
if(EleFound == 0){
strcpy(C[nElemC],A[i]);
//Increment the nEleC
nElemC++;
}
}
//Print the difference
for(int i = 0; i < nElemC; i++)
printf("%s ", C[i]);
return nElemC;
}
int setComplement(String *A, String *B, String *C, int nElemA, int nElemB){
//Now here we have to get the elements from B which are not present in A that is A complement
//Set the nElemc to zero
int nElemC = 0;
//Iterate over the B
for(int i = 0 ; i<nElemB ; i++){
//Set ele found to 1 in case the element from b is found in a
int EleFound = 0;
//Now iterate over the A
for(int j = 0 ; j < nElemA ; j++){
if(strcmp(B[i],A[j]) == 0){
//Set elefound to 1 in case the element from b is present in a
EleFound = 1;
//Get out of the loop
continue;
}
}
//Check if Elefound is 0 . If yes then add the element in differnce else ignore it
if(EleFound == 0){
strcpy(C[nElemC],B[i]);
//Increment the nEleC
nElemC++;
}
}
//Print the difference
for(int i = 0; i < nElemC; i++)
printf("%s ", C[i]);
return nElemC;
}
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)