sum all numbers from 1 to 10 in csharp

You can use a for loop to iterate through the numbers from 1 to 10 and add them together. Here's an example code block:

main.cs
int sum = 0;
for (int i = 1; i <= 10; i++)
{
    sum += i;
}
Console.WriteLine("The sum of the numbers from 1 to 10 is: " + sum);
130 chars
7 lines

In this code, we initialize a variable sum to 0, then use a for loop to iterate through the numbers 1 to 10. For each number, we add it to sum. After the loop is finished, we print the value of sum to the console. The output should be:

main.cs
The sum of the numbers from 1 to 10 is: 55
43 chars
2 lines

gistlibby LogSnag