Saved Bookmarks
| 1. |
Write an algorithm to check the given number is a power of 2. |
|
Answer» Step 1: start Step 2: input n Step 3: let temp = n Step 4: let status =1 Step 5:while(temp>2)repeat If (temp%2 = 1) then Status = 0 Goto step 6 Else temp = temp/2 end if end while step 6: is (status = 1) then print n,"is power of 2" else print n,"is not power of 2" end if step 7:stop |
|