Message from C, C++ discussions
November 2019
— I would like to help you but can you please explain more in detail what your program should do?
Yeah. This program should find what is the last number to sum to the sequence of positive integers so the final sum is > 100
— Alright
— Just use a while loop
— How can I write highlighted code here?
— ``` code and the also 3x`
— Ok thanks
— What about
register unsigned num = 0u, last = 0u; for(;;) { ++last; num+=last; if(num + last > 100) { num = last; break; } }
— Then num should be the last number
— Even more simpler
register unsigned last = 0u; for(register unsigned num = 0;;++num) {last+=num; if(num + last > 100) break; }
— reinterpret_cast
For example
#include <stdio.h>
#include <math.h>
main ()
int S;
int V;
S, V = 0;
while (!S > 100)
V = V + 1;
S = S + V;
printf ("The number is %d", V)
— Can this be considered correct?