Jumaat, 18 Februari 2011

Looping

1. What happens in a while loop if the control condition is false (i.e., zero) initially.

2. How does the break statement provide better control of loops?

3. What is wrong with the following loop:
a. while(n<=100) {sum+=n*n; }

4. if s is a statement, and e1, e2, and e3 are expressions, then what is the difference between the program fragment: a. for(e1,e2,e3) {s;}
And the fragment :
b. e1; while(e2) {s; e3; }



5. Describe the output from this program
int main()
{for(int i=0; i<8;i++)
if (i%2 ==0) cout<else if (i%3 ==0) cout<else if (i%5 == 0) cout<<2*i-1<<”\t”;
else cout<}

2 ulasan:

  1. soalan 5 dy minta aper cek?? pelik jer soklannyer..

    BalasPadam
  2. sori tersilap code tu..
    saya dah betulkan.
    soalan 5, minta awak 'trace' outputnya.

    BalasPadam