sum of square of first n odd & even no

October 6, 2010 at 09:26:52
Specs: Windows XP
it is a unix program . pls help with the answer

See More: sum of square of first n odd & even no

Report •

October 6, 2010 at 18:18:41
Sounds like homework, so I won't give you the answer, but I can offer some suggestions and hints to get you headed in the right direction.

There's lots of different unix languages available, so you can really pick and choose which one you want to write it in, unless your assignment specifies a particular one. I use c shell, so if you are interested in using that, you can find a useful manual here:
A lot of people don't recommend it though, so you'll probably get other suggestions here.

The mathematical algorithm I would recommend would be to loop over a summing formula. Define a variable as the square of a given integer, i.e. a = i^2 then define a second variable as the running total. This can be calculated as a sum of its current value and 'a'. Finally, you'll have to increment 'i', for use in the next iteration. As the loop keeps running the running total will gradually sum up all the squares of the given integers. You'll also have to set up the loop so that it stops running once it gets to however many integers you want summed. And if this is all the program is required to do you'll then need it to output the calculated value. I would also recommend outputting a message saying what the output number is, e.g. "The sum of the square of the first 4 odd integers is 84."
You can also start to implement more fancy things, like reading in inputs, e.g. 'n', odd or even, etc, or asking the user questions and using the typed response to determine the parameters of the program, and so on. The program can be as simple or complex as you would like.

Hope that's given you enough to go on. Have a go at coding it up, and make sure you test it. If you're having trouble getting things to work, post the code you have and I or other users can offer suggested improvements and syntax fixes.

Good luck. :)


Report •
Related Solutions

Ask Question