Determining value after loop is executed??!!

Can somebody show me how to do this with steps? not understanding it, i have a test tomorrow!!

Determine the value in total after each of the following loops is executed:

a. total = 0;
for (i = 1; i <= 10; i = i + 1)
total = total + 1;

b. total = 1;
for (count = 1; count <= 10; count = count + 1)
total = total * 2;

c. total = 0
for (i = 10; i <= 15; i = i + 1)
total = total + i;

d. total = 50
for (i = 1; i <=10; i = i + 1)
total = total – i;

e. total = 1
for (icnt = 1; icnt <= 8; ++icnt)
total = total * icnt;

f. total = 1.0
for (j = 1; j <= 5; ++j)
total = total / 2.0;
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>

using namespace std;

int main()
{
    int total = 0;

    for(unsigned short i = 1; i <= 10; i++)
    {
        total++;
    }

    cout << "total = " << total << endl;

    total = 1;

    for(unsigned short count = 1; count <= 10; count++)
    {
        total *= 2;
    }

    cout << "total = " << total << endl;

    total = 0;

    for(unsigned short i = 10; i <= 15; i++)
    {
        total += i;
    }

    cout << "total = " << total << endl;

    total = 50;

    for(unsigned short i = 1; i <= 10; i++)
    {
        total -= i;
    }

    cout << "total = " << total << endl;

    total = 1;

    for(unsigned short icnt = 1; icnt <= 8; ++icnt)
    {
        total *= icnt;
    }

    cout << "total = " << total << endl;

    double totalDouble = 1.0;

    for(unsigned short j = 1; j <= 5; ++j)
    {
        totalDouble /= 2.0;
    }

    cout << "total = " << total << endl;

    cout << endl;

    return 0;
}


That seems to work...
Topic archived. No new replies allowed.