Answer to Question #162367 in C++ for Abhishek Prasad

Question #162367

The following program fragment is supposed to count the sum of the numbers divisible by 7 read until the number -1 is encountered (upon which the program exits after printing the value of the sum). For example, if the input is "1 4 7 2 42 -1", the output should be 49.


IMPORTANT NOTE -> all answers should be without semicolons and any spaces. special requests in these cases won’t be considered.


int req_sum = 0;

int x=0;

while(B1){

cin >> x;


if (x%7==0) B2;


}


cout<<req_sum<<endl;


1
Expert's answer
2021-02-09T15:26:57-0500
int req_sum=0
    int x=0
    while(x != -1){
        cin >> x
        if (x%7==0)
            req_sum+=x
    }
    cout<<req_sum<<endl

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment