What is the total number of multiplication performed after applying common…

What is the total number of multiplication performed after applying common subexpression elimination to the given code:
a = p*3 + q*5
for(int i  = 0; i<198; ++i){
if((z+i)%2 == 0){
b = p*3 + (z*i);
}else{
c = q*5 + c;
}
}

Answer: 101x = p*3 y=q*5 a = x + y for(int i = 0; i<198; ++i){ if((z+i)%2 == 0){ b = x + (z*i); }else{ c = y + c; } } inside loop there will be 99 multiplication as no…

Attempted by 5 students.

Show answer & explanation

Correct answer: 101

x = p*3
y=q*5
a = x + y
for(int i  = 0; i<198; ++i){
if((z+i)%2 == 0){
b = x + (z*i);
}else{
c = y + c;
}
}

inside loop there will be 99 multiplication as no matter whether z is even or odd, there are total 99 odd values possible and 99 even values hence if will run 99 times and 2 multiplication are outside loop

Explore the full course: Compiler Design

Loading lesson…