Liste des Groupes | Revenir à cl c |
On 19/03/2025 20:45, DFS wrote:It occurs to me now that maybe you're sorting in case the numbers aren't as consecutive as they're supposed to be, in which case it can still be done without sorting, but it's very, /very/ slightly harder because you have to keep track of the lowest and highest seen so far:On 3/19/2025 4:53 AM, Keith Thompson wrote:<snip>
Like Keith, I don't usually use scanf.I'm actually using>
scanf() for integer input, something I wouldn't do in normal code
(because the behavior is undefined if the scanned value is out
of range). This is a rare case where it's safe to assume that
stdin has nothing harmful.
>
>
My very 1st submission for 'Missing Number' was accepted, but each use of scanf() generated a warning:
My preference is to read the number into a text buffer using fgets, and then convert it using strtoul if I can, or strtol if I have to allow for negatives.
//identify the missing number in a set of consecutive integersNot sure why you're sorting and malloc-ing.
Loop through the input, adding as you go.
Let the first number be x.
Let the last number be y.
Let the total of all numbers be t.
Let m = ((y*(y+1))-(x*(x+1)))/2 - t;
"The missing number is: %lld\n", m
Les messages affichés proviennent d'usenet.