Thursday, July 30, 2009

Can someone explain to me that C# loop please?

using System;





class ProdSum


{


public static void Main()


{


int prod;


int sum;


int i;





sum = 0;


prod = 1;





for (i = 1; i %26lt;= 10; i++)


{


sum = sum + i;


prod = prod * i;


}


Console.WriteLine("Sum is " + sum);


Console.WriteLine("Product is " + prod);


Console.WriteLine("total is " + i);





}


}





The output is :





Sum is 55


Product is 3628800


Total is 11





I understand that it will loop until it reaches 10


but I can't figure out how it gets 55 %26amp; the product??





Thanks

Can someone explain to me that C# loop please?
huh?





1+2+3+4+5+6+7+8+9+10 = 55


1*2*3*4*5*6*7*8*9*10 = 3628800

floral arrangements

No comments:

Post a Comment