How do I solve this?
One way is to just compare the new sum to k before incrementing n and adding it to the sum.
#include <stdio.h>
int main()
{
unsigned k, l, n;
while (printf("k .. .....: "), scanf("%u", &k) > 0 && k != -1u)
{
for (l = 0, n = 0; l+n < k; l += ++n) ;
printf("1.. %d... .. %d....\n", n, l);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.