2

Following would be the steps assuming 8 students are in the room 1. Each of them would have the number 1 in their mind and 8 of them would be standing 2. You add the number in your pair's mind (in this case is 1 in each of their mind and the resultant would be 2) and one of you in your pair sits down. 3. After the pairing, 4 people would be standing with 2 ...


2

Right before bool sorted = false;, you have return true;. You give a return value before anything else happens, so your function does exactly that: it returns that value and stops executing any further code.


1

The only time this if (ptxt[i] >= 'Z' && isupper(ptxt[i])) will evaluate to true is when ptxt[i] is 'Z'. There is no other (upper case) letter that can be both. (Similarly this else if (ptxt[i] >= 'z' && islower(ptxt[i])) is only true for 'z'). Think about why isupper() and islower() are sufficient. Remember too that if isupper() or ...


1

Bigger picture: In programming, there are certain tasks that appear over and over in some form or another. Sorting data is one of them. Linked lists are another. These tasks have been analyzed extensively and repeatedly, in order to find more and more efficient ways to do them. Today, when encountering one of these tasks, there's no need to reinvent the ...


1

In the problems that you will find in cs50, you will not find any difference in speed especially in C, as you well say the recursive solution requires more memory usage. We simply use a recursive solution because it can be simpler in terms of readability of the code. In certain that in the languages interpreted as php or phyton a recursive solution can take ...


1

What about this 5105105105105100? 1*2 + 5*2 + 0*2 + 1*2 + 5*2 + 0*2 + 1*2 + 0*2 2 + 10 + 0 + 2 + 10 + 0 + 2 + 0 2 + 1 + 0 + 2 + 1 + 0 + 0 + 2 + 0 = 8 8 + 5 + 0 + 1 + 5 + 0 + 1 + 5 + 0 = 25 The checksum is not ending with 0, but cs50 online judge says it's a valid mastercard. I'm totally confused.


1

371449635398431 is a valid AMEX card. From this post: 3 7 1 4 4 9 6 3 5 3 9 8 4 3 1 Okay, let’s multiply each of the underlined bold digits by 2 7*2 + 4*2 + 9*2 + 3*2 + 3*2 + 8*2 + 3*2 That gives us: 14 + 8 + 18 + 6 + 6 + 16 + 6 Now let’s add those products' digits (i.e., not the products themselves) together: 1 + 4 + ...


1

Where you got 107, I did the maths without calculator, and got to 90. Keep in mind that the digits to double start with the second to last digit (so first digit could be regular or doubled), and that a doubled 8 results in 1+6=7. [edit] Well, it's 80, and the difference of 27 being a multiple of 9 indicates you are treating doubled larger numbers wrong. 2*...


Only top voted, non community-wiki answers of a minimum length are eligible