1 / 33

Powers of Two: Trace

This code snippet demonstrates how to print the powers of two that are less than or equal to 2^N. The program starts with an integer 'i' at 0 and a value 'v' initialized to 1. It increments 'i' while printing the current value of 'i' and 'v', doubling 'v' each time. For N = 6, it will print powers of two from 2^0 to 2^6, alongside their respective indices. This exercise illustrates the concept of exponential growth in numbers through simple iterative logic.

saburo
Télécharger la présentation

Powers of Two: Trace

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } N = 6

  2. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i 0 int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } N = 6

  3. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v 0 1 int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } N = 6

  4. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } N = 6

  5. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } N = 6

  6. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 N = 6

  7. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 N = 6

  8. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true N = 6

  9. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true N = 6

  10. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 N = 6

  11. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 N = 6

  12. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true N = 6

  13. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true N = 6

  14. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 N = 6

  15. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 N = 6

  16. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true N = 6

  17. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true N = 6

  18. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true 4 N = 6

  19. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true 4 16 N = 6

  20. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true 4 16 true N = 6

  21. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 4 16 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true 4 16 true N = 6

  22. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 4 16 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true 4 16 true 5 N = 6

  23. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 4 16 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true 4 16 true 5 32 N = 6

  24. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 4 16 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true N = 6

  25. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 4 16 5 32 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true N = 6

  26. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 4 16 5 32 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 6 N = 6

  27. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 4 16 5 32 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 6 64 N = 6

  28. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 4 16 5 32 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 6 64 true N = 6

  29. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 4 16 5 32 6 64 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 6 64 true N = 6

  30. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 4 16 5 32 6 64 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 6 64 true 7 N = 6

  31. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 4 16 5 32 6 64 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 6 64 true 7 128 N = 6

  32. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 4 16 5 32 6 64 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 6 64 true 7 128 false N = 6

  33. Powers of Two: Trace • Ex. Print powers of 2 that are  2N. • Increment i from 0 to N. • Double v each time. i v i <= N 0 1 1 2 2 4 3 8 4 16 5 32 6 64 0 1 true int i =0; int v =1; while(i <= N){ System.out.println(i +" " + v); i = i +1; v =2* v; } 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 6 64 true 7 128 false N = 6

More Related