HElp plsss!!!

C / C++ Discuss, HElp plsss!!! at Programmers Lounge forum; Please help me!!! Im a 1st yr IT student and seems I dont understand the problem that my instructor have ...


Go Back   Gamerz Needs - For All Your Gaming Needs! > Technology Zone > Programmers Lounge > C / C++
Forgot Password? | Sign Up!

Notices

Advertisement
   

Reply
 
Bookmark this Thread Tools Display Modes
  #1  
Old 10-11-2008, 01:27 AM
GraNAdoEspadA's Avatar
Metal Axe
 
Last Online: 11-10-2008 07:10 AM
Join Date: Feb 2006
Location: Land of Happiness
Age: 18
Posts: 72
Thanks: 15
Thanked 1 Time in 1 Post
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 6
GraNAdoEspadA is on a distinguished road
Points: 322.28
Bank: 520.36
Total Points: 842.64
HElp plsss!!!

Please help me!!!

Im a 1st yr IT student and seems I dont understand the problem that my instructor have given to me...

This is her problem given to me:

Write a program that would input a positive integer N and then outputs the sum of the squares of the integers from 1 to N. For example, if the input is 5 the output should be 55. (that is 1^2 + 2^2 + 3^2 + 4^2 + 5^2 = 55)

please help me I wanna answer it so badly but i dunno what is the exact formula...

I have logical error in my brain! Thanks...
__________________

Im On fIre
  #2  
Old 10-11-2008, 01:59 AM
Sean's Avatar
Gunbound UnderGround Level 3
 
Last Online: Today 02:00 AM
Join Date: Aug 2005
Age: 20
Posts: 4,402
Thanks: 2
Thanked 8,568 Times in 794 Posts
Nominated 33 Times in 17 Posts
Nominated TOTW/F/M Award(s): 1
Latest Blog:
Rep Power: 23
Sean has a spectacular aura aboutSean has a spectacular aura aboutSean has a spectacular aura about
Points: 41,586.56
Bank: 259,569.03
Total Points: 301,155.59
meat vomit - Ken I like people that are switched on up there. - Slugsnack I need no cells hack - huseyin No Message - goblin4u No Message - ahmedangel 
after all those bans, you still get POTM - pilotcs I love how you release only 1 new item to a hack, and get 250 more thanks. gay. =) - pilotcs Hmm. Banana. - Goku Thanks for the great MH ^^ - Adamaniac AwsOme HaCkEr - rebelife56 
I wonder if yours is longer. :) - Crumpeteer_ You Are a Cool friend so good luck and dont forget to eat my burger :)) - humam1992 A nice cold one on me! - kronikill421 best haxor - Plazma No Message - Yokerr 
GregP123 Ownz + Sean Ownz - GregP123 Cheers Sean! - chaosnite192 A beer for awesomeness! - Roguez Keep up the great works on the hacks. - Kyle No Message - jordandll 
Green - JMT420 Gold - Andrex2x Burgundy - Adamaniac Black - gogo_salem Black - shaolin786 
Dark Blue - aaronchanhongsen Gold - bmwm4 Green - hyperzuz Black - gogo_salem Gold - Roguez 
Burgundy - Torai Gold - Denipie 
Quote:
Write a program that would input a positive integer N and then outputs the sum of the squares of the integers from 1 to N. For example, if the input is 5 the output should be 55. (that is 1^2 + 2^2 + 3^2 + 4^2 + 5^2 = 55)
hmm...

so...

Get Input

You could do this in a loop

asm style:

.WHILE (input > 0)
mov ecx, input ;e.g. 5
imul ecx, ecx ;5 * 5 (square)
sub input, 1
add output, ecx
.ENDW

not too certain on c++ syntax.

but the algorithm would be:

Get Input
Store Input into a Variable (e.g. Input)
Create a loop that loops while Input > 0
Inside loop have it multiply current value stored in Input by itself (to square it) and then add that to an output variable. Then decrement value stored in Input.
Then when loop is exited, output the # that's currently in the output variable.

Code:
'Name: Sean
'Date: October 11, 2008
'Description: Write a program that would input a positive integer N and then outputs the sum of the squares of the integers
'             from 1 to N. For example, if the input is 5 the output should be 55. (that is 1^2 + 2^2 + 3^2 + 4^2 + 5^2 = 55)
Option Explicit

Sub GzNProblem()

    Dim InputVar As Long
    Dim OutputVar As Long
    Dim OrigInput As Long
    
    InputVar = InputBox(\"Enter a positive integer\", \"Get positive integer\")
    OrigInput = InputVar
    If InputVar >= 0 Then
        Do Until (InputVar = 0)
            OutputVar = OutputVar + (InputVar * InputVar)
            InputVar = InputVar - 1
        Loop
        MsgBox (\"You entered: \" & OrigInput & \". The result is: \" & OutputVar), 32, \"Result\"
    Else
        MsgBox (\"You entered a negative integer! Only enter a positive integer.\"), 32, \"Error\"
    End If
    
End Sub
This would be the VB code for your problem. Just tested it out, works. (the random slashes in the code were added by GzN - remove them if you want to compile it).
__________________


Hacks of mine that you can get if you buy premium:
  • Gunz Multi Hack (IJJI)
  • Wolfteam Multi Hack (WIS, WLS)
  • Gunbound Multi Hack (GBNA, GIS, GBEU)
  • Rakion Legit Hack (RIS, RLS, RSS)
So support GzN, buy premium, and start hacking today!

Last edited by Sean; 10-11-2008 at 02:40 AM..
The Following User Says Thank You to Sean For This Useful Post:
GraNAdoEspadA (10-11-2008)
  #3  
Old 10-11-2008, 02:28 AM
GraNAdoEspadA's Avatar
Metal Axe
 
Last Online: 11-10-2008 07:10 AM
Join Date: Feb 2006
Location: Land of Happiness
Age: 18
Posts: 72
Thanks: 15
Thanked 1 Time in 1 Post
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 6
GraNAdoEspadA is on a distinguished road
Points: 322.28
Bank: 520.36
Total Points: 842.64
What!!! thanks a lot... I understand a bit of the concept but?

Im just just a beginner to uses Simple C++ like(#include<stdio.h>)

thnksss.......
__________________

Im On fIre
  #4  
Old 10-11-2008, 09:49 AM
1k Points Wasted
 
Last Online: Yesterday 02:08 PM
Join Date: Aug 2006
Location: over there
Posts: 2,219
Blog Entries: 6
Thanks: 48
Thanked 172 Times in 134 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Latest Blog: Very random blog entries (based on time)
Rep Power: 13
cosmeo3000 will become famous soon enoughcosmeo3000 will become famous soon enough
Points: 6,002.26
Bank: 89,660.72
Total Points: 95,662.98
Black - cosmeo3000 
Send a message via MSN to cosmeo3000
In C++:
Code:
#include <iostream>

using namespace std;

int main()
{
	int n = 0;
	int nTotalSum = 0;

	cout << \"Choose a number: \";
	cin >> n;
	if(n < 0)
	{
		cout << \"Since your number is negative, it will be converted to positive.\";
		n *= -1;
	}
	cout << endl;
	
	for(int i = 0; i <= n; i++)
	{
		nTotalSum += (i * i);
	}

	cout << \"The total is \" << nTotalSum << endl;
}
Same deal here. Remove the \ in the code if you want to compile
__________________

Dam my other one won't animate for some reason o_O

Last edited by cosmeo3000; 10-11-2008 at 09:53 AM..
The Following User Says Thank You to cosmeo3000 For This Useful Post:
GraNAdoEspadA (10-13-2008)
  #5  
Old 10-13-2008, 01:42 AM
GraNAdoEspadA's Avatar
Metal Axe
 
Last Online: 11-10-2008 07:10 AM
Join Date: Feb 2006
Location: Land of Happiness
Age: 18
Posts: 72
Thanks: 15
Thanked 1 Time in 1 Post
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 6
GraNAdoEspadA is on a distinguished road
Points: 322.28
Bank: 520.36
Total Points: 842.64
Thnaks man you give me the idea... I understand now the processess....
__________________

Im On fIre

Last edited by GraNAdoEspadA; 10-13-2008 at 08:07 PM..
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Advertisement
   


Main Navigation
Home
GzN Forums
GzN Games
GzN News
Top Games
GzN Cheats
GzN Articles
GzN Reviews
GzN Downloads
User Control Panel
Advertising
RSS Feed
2Moons
Adventure Quest
AirRivals
America's Army
Anarchy Online
Archlord
Audition
Battlefield Series
Cabal Online
Call Of Duty Series
Combat Arms
Conquer Online
Counter Strike
Day of Defeat
Deicide Online
Diablo Series
Doom Series
Drift City
Enemy Territory
Eudemons Online
Final Fantasy
Flyff (Fly For Fun)
General Game Discussion
Ghost Online
Granado Espada
Grand Theft Auto Series
Guild Wars
Gunbound
Gunz Online
Habbo Hotel
Half-Life 2
Hero Online
KartRider
Knights Online
Maple Story
Medal of Honor
MU Online
Neopets
Pangya
Quake Series
Ragnarok Online
Rappelz
Rakion
Red Orchestra
Rose Online
Runescape
Scions of Fate
Silkroad Online
Sims Series
Soldier Front
Starcraft
Tales of Pirates
Tibia
The Ship
Trickster Online
TS Online
Unreal Tournament
War Rock
WolfTeam
World of Warcraft & Series
Affiliates
COD4 Hacks
BF2 Hacks


All times are GMT -8. The time now is 05:31 PM.