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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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;

}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Algebraic Expressions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY