For the algorithm below compute the number of multiplication

For the algorithm below, compute the number of multiplications performed, as well as the final value of s.

what is number of Multiplications?

final value of s?

s 0

for i  {1, 2, 3, 4} do

    

p 1

    

for j  {1, ... , i}do

    

p p · 2

s s + p

s 0

for i  {1, 2, 3, 4} do

    

p 1

    

for j  {1, ... , i}do

    

p p · 2

s s + p

Solution

Sample c++ code to test:

#include <iostream>

using namespace std;

int main()
{
int s =0;
for(int i=1;i<5;i++)
{
int p = 1;
for(int j=1;j<=i;j++)
{
p = p *2;
}
s = s+ p;
}
cout << \"s : \" << s << endl;

return 0;
}

what is number of Multiplications?

10

final value of s?

30

For the algorithm below, compute the number of multiplications performed, as well as the final value of s. what is number of Multiplications? final value of s?
For the algorithm below, compute the number of multiplications performed, as well as the final value of s. what is number of Multiplications? final value of s?

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site