+ 1

whats the most efficient way to code something that writes 1 3 7 12 18... etc

i need it to infinitly increase by a number that increases by one after every loop . i have a piecr of public code that requires such

17th Dec 2016, 7:08 PM
chorditronix
chorditronix - avatar
5 ответов
+ 2
int i = 1; int result =0; while ( i <100 ) { result += i ; Console.WriteLine( result); i++; } //this prints 100 numbers....if you need infinite numbes use while ( true ) instead
17th Dec 2016, 7:38 PM
HAL8999++;
HAL8999++; - avatar
+ 2
i think you want increase the addition number by one .so try this code . int x =1; for(int i =1;i<100;i++) { Console.WriteLine(i); i += x; x ++; } this will print 1, 3 ,6 ,10 ,15 ,21
17th Dec 2016, 7:45 PM
Ahmed Gamal
Ahmed Gamal - avatar
+ 1
ah, yes thanks
17th Dec 2016, 7:46 PM
chorditronix
chorditronix - avatar
0
the first loop adds one, the second adds 2 the third adds 3 and so on forever
17th Dec 2016, 7:14 PM
chorditronix
chorditronix - avatar
0
i need more than that, i need 1+2+3+4+5 and so on, so x = 1 y = 2, x + y = z, y++ then z+y then y++ and so on
17th Dec 2016, 7:40 PM
chorditronix
chorditronix - avatar