63 796
Assignments Done
99,4%
Successfully Done
In August 2018

Answer to Question #32664 in C# for Jei Valcorza

Question #32664
Write a program that reads in a number n and then outputs the sum of the squares of the numbers from 1 to n. If the input is 3, for example, the output should be 14, because:
1²+2²+3² = 1 + 4 + 9 = 14.
Expert's answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Question32664
{
class Program
{
//main function
static void Main(string[] args)
{
int n,sum=0;//declare variable
Console.Write("Enter n= ");//input number
n = int.Parse(Console.ReadLine());//read number from keyboard
for (int i = 0; i < n; i++) {
sum += (i + 1) * (i + 1);//add to sum
}
//show result
Console.Write("Result = " + sum.ToString());
Console.ReadLine();//delay
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions