- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
Software programming learning aide
CS50 threads to aide as a supplementary resource › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 1: [C] – Data Types, Operators, Conditional Statements, Loops, and Command Line › Pset1- Credit: Length of the number by continuously dividing by 10
Tagged: Integer divison, integer type
// Get card number long n = get_long("Number: "); // Count length int i = 0; long cc = n; while (cc > 0) { cc = cc / 10; i++; } Source: https://medium.com/swlh/cs50-pset-1-credit-c7996fb0a837
Source: https://medium.com/swlh/cs50-pset-1-credit-c7996fb0a837
It is mentioned:
We can then determine the length of the number by continuously dividing by 10, effectively knocking a digit off the end each time through the while loop until there are no digits left.
What I see is that cc = cc / 10 will keep on running with cc tending towards smaller and smaller fraction but not zero.
Suppose, finally afer cc/10, left with 9. Then 9/10, which is a fraction and not an integer. Seeking insight what happens at this stage.
I understand cc too an integer type (long integer), cc cannot be fraction.
Reply
https://cs50.stackexchange.com/questions/41921/pset1-credit-length-of-the-number-by-continuously-dividing-by-10[learn_press_profile]