Hello. I want to make a program that will show the sum of the squares of numbers
For example User First Inputs Number: 2
And then inputs number: 5
The program calculates the sum of the numbers between these two numbers 2 and 5 are included. 2*2+3*3+4*4+5*5=54. The Output should be 54
I made the program but it worked a little bit wrong:
Here is my code:
Module Module1
Sub Main()
Dim M, N As Integer
Console.Write("Input 1st Number: ")
M = CInt(Console.ReadLine())
Console.Write("Input 2nd Number: ")
N = CInt(Console.ReadLine())
square(M, N)
End Sub
Function square(ByVal X As Integer, ByVal Y As Integer) As Integer
Dim A As Integer
Dim B As Integer
For X = 0 To Y
A = X * X
B = Y * Y
Next
Console.WriteLine("Output: " & A + B)
Return A
Return B
End Function
End Module
Can you help me what is wrong in this program. And how can I fix it? Thanks in Advance :)
cplusplus.com is the name of the site, but the thing is, In this web site I saw other questions from Visual Basic. On the other hand there is also also UNIX/Linux Programming, Windows programming. So I hope you can give me some ideas on the algorithm, It is Ok even if you give me c++ based algorithm I could figure it out on Visual Basic.
I really need help on that.
UNIX/Linux and Windows aren't programming languages. Both subforums are about C++ only.
The algorithm is trivial, as it equals the problem itself:
for each number in the range: square it and add it to the sum.