# Question & Answer: Question 4 Determine the value in total after each of the following loops i…..

Dev C++

Question 4 Determine the value in total after each of the following loops is executed a) double total -0: for (int i-l ; i

//final value of total is given below in output

a.cpp ——–>

#include<iostream>
using namespace std;
int main()
{
double total=0;
for(int i=1;i<=10;i=i+1)
total=total+1;
cout<<total;
return 0;
}

Output :-

10

b.cpp ——>

#include<iostream>
using namespace std;
int main()
{
double total=0;
for(int count=1;count<=10;count)
total=total*2;
cout<<total;
return 0;
}

Output :-

No Output

//total remain same 0 till infinite time

c.cpp ——>

#include<iostream>
using namespace std;
int main()
{
double total=0;
for(int icnt=1;icnt<=8;++icnt)
total=total*icnt;
cout<<total;
return 0;
}

Output :-

0

d.cpp ——>

#include<iostream>
using namespace std;
int main()
{
double total=1.0;
for(int j=1;j<=4;++j)
total=total/2.0;
cout<<total;
return 0;
}

Output :-

0.0625

e.cpp——>

#include<iostream>
using namespace std;
int main()
{
double total=0;
int i=1;
while(total<10)
{
i++;
total=total+i;
}
cout<<total;
return 0;
}

Output :-

14

f.cpp ——>

#include<iostream>
using namespace std;
int main()
{
double total=0;
int i=1;
while(i<100)
{
total+=1;
i+=2;
}
cout<<total;
return 0;
}

Output :-

50

g.cpp—–>

#include<iostream>
using namespace std;
int main()
{
double total=0;
int i=1;
while(i<100)
{
total+=i;
}
cout<<total;
return 0;
}

Output —->

No output as while loop will run infinite times becasue i will remain always less then 100

so total will be infinte.

h.cpp —->

#include<iostream>
using namespace std;
int main()
{
double total=0;
int i=10;
do
{
total+=20;
}while(i<=5);
cout<<total;
return 0;
}

Output —–>

20

i.cpp ——>

#include<iostream>
using namespace std;
int main()
{
double total=0;
int i=10;
do
{
total+=10;
}while(i<=100);
cout<<total;
return 0;
}

Output —->

No output so total will be infinite this time

j.cpp—–>

#include<iostream>
using namespace std;
int main()
{
double total=0;
int i=10;
do
{
total+=10;
i++;
}while(i<=100);
cout<<total;
return 0;
}

Output —–>

910