Hello,
Could you explain me what this statement means? I am confused with k/=2 as iteration statement. for (int k = p; k > 0; k /= 2)
Thanks
beatlea
0
Newbie Poster
Recommended Answers
Jump to PostInteger division will always be zero as "C" floors it.
Odd number: 5
5 / 2 = 2
2 / 2 = 1
1 / 2 = 0Even number: 4
4 / 2 = 2
…
2 / 2 = 1
1 / 2 = 0
Jump to Postwell, if k = 10 or 11 after 1st iteration it becomes 5 then 2 then 1 and then 0 to exit.
I guess stephen said that this halving occurs once every iteration
EDIT: Too late
All 6 Replies
stephen3200
0
Newbie Poster
beatlea
0
Newbie Poster
stephen3200
0
Newbie Poster
Clockowl
56
Posting Whiz
Prabakar
77
Posting Whiz
beatlea
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.