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;
int req_sum=0
int x=0
while(x != -1){
cin >> x
if (x%7==0)
req_sum+=x
}
cout<<req_sum<<endl
Comments
Leave a comment