Please code C#
7. Write a program that can calculate the sum of all numbers between 1 and 1000 inclusive (including 1 and 1000)
Code Screenshot :
Executable Code:
using System;
class sum {
public static void Main (string[] args) {
//Declaring required variable
int sum = 0;
//Execute loop until 1000
for(int i = 1; i <= 1000; i++){
//Calculating the
sum
sum += i;
}
//Print the result
Console.WriteLine("Sum of all numbers b/w 1 to 1000 is
{0} ",sum);
}
}
Sample Output :
Please comment
below if you have any queries.
Please do give a thumbs up if you liked the answer thanks
:)
Get Answers For Free
Most questions answered within 1 hours.