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
  • using c/c++ Q1 (15 Marks) Console Application for Student Data 1- Write a function named Average...

    using c/c++ Q1 (15 Marks) Console Application for Student Data 1- Write a function named Average that Receives two integer numbers as parameter and returns the average Is used in a main function. Main() stays in a loop and asks user to enter 2 numbers and then shows the average using the Average function above Define a class named Student with following members: private data: 2 grades and a GPA (average). public constructor to initialize the members a public function...

  • JAVA PROG HW Problem 1 1. In the src −→ edu.neiu.p2 directory, create a package named...

    JAVA PROG HW Problem 1 1. In the src −→ edu.neiu.p2 directory, create a package named problem1. 2. Create a Java class named StringParser with the following: ApublicstaticmethodnamedfindIntegerthattakesaStringandtwocharvariables as parameters (in that order) and does not return anything. The method should find and print the integer value that is located in between the two characters. You can assume that the second char parameter will always follow the firstchar parameter. However, you cannot assume that the parameters will be different from...

  • This is a standard C++ programming assignment using a command line g++ compiler or the embedded...

    This is a standard C++ programming assignment using a command line g++ compiler or the embedded one in zyBooks. No GUI forms and no Visual Studio. No external files and no databases are used. There is only one object-oriented program to complete in this assignment. All code should be saved in a file named ExamScoresUpdate.cpp, which is the only file to submit for grading. No .h files used. The .cpp file contains main() and two classes, ExamScores and DataCollector. There...

  • 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
ADVERTISEMENT