+ 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
5 Respostas
+ 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
+ 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
+ 1
ah, yes thanks
0
the first loop adds one, the second adds 2 the third adds 3 and so on forever
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