Question

"Write an application named sum500 that sums the integers from 1 to 500." (Joyce Farrel, Microsoft...

"Write an application named sum500 that sums the integers from 1 to 500." (Joyce Farrel, Microsoft Visual c# 2015: an introduction to object-oriented programming)

this pe.9 from chapter 5. We aren't expted to use anything fancy, maybe just a for loop or nested loops that's about it. Thank you. Please use c#.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;

namespace program
{
class sum500
{
static void Main(string[] args)
{
int i, sum = 0,n=500;
for (i = 1; i <= n; i++)
{
sum = sum + i;
}
Console.WriteLine("\nSum of 500 Numbers : " + sum);

}
}
}

The above C# program is the simplest way to add integers from 1 to 500. The key thing is loop.

The structure of program is same as any other C# program .

First include System by using keyword

Then declare a class named sum500 . Your code goes inside the main function. The program starts execution from here.

declare a variable i whose value will vary from 1 to 500 in the loop. Inititalise a variable sum as 0. It will store the sum of numbers

start the loop from i=1 till i=500

Value of i is added to sum each time the loop executes

So in the end we get sum=1+2+3+4........500

Then print the sum . AS SIMPLE AS THAT. hope it helped you.

Add a comment
Know the answer?
Add Answer to:
"Write an application named sum500 that sums the integers from 1 to 500." (Joyce Farrel, Microsoft...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How does this article relate to the factors of productions in economics? From Music to Maps,...

    How does this article relate to the factors of productions in economics? From Music to Maps, How Apple’s iPhone Changed Business Ten years ago, hailing a cab meant waiving one's arm at passing traffic, consumers routinely purchased cameras, and a phone was something people made calls on. The iPhone, released a decade ago this month, changed all of that and more, sparking a business transformation as sweeping as the one triggered by the personal computer in the 1980s. Apple Inc.'s...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT