Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 14-08-2007, 08:29 PM   #1 (permalink)
In The Zone
 
Join Date: Jul 2006
Posts: 236
Default c++ program

Hey,

can u guys tell me how to create a cpp program to print all the armstrong numbers within a given limit.?
sai_cool is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 14-08-2007, 08:36 PM   #2 (permalink)
>:)I-):(|)8-X
 
Charan's Avatar
 
Join Date: Sep 2004
Location: ಬೆಂಗಳೂರು (Bengaluru)
Posts: 3,512
Default Re: c++ program

Is thats a assignment given by your school/college ?
__________________
i5 2400 | DH67BL | G.Skill Ripjaw 4 GB | FSP SAGA II 500W | CM 430 Black Elite | MSI R6850 Cyclone PE/OC | XBox 360 Controller | 21.5" Samsung Sync Master 2233 | 4 Mbps UL
Charan is online now  
Old 14-08-2007, 09:01 PM   #3 (permalink)
C# Be Sharp !
 
Zeeshan Quireshi's Avatar
 
Join Date: Jun 2006
Location: Toronto
Posts: 1,805
Default Re: c++ program

Quote:
Originally Posted by sai_cool
Hey,

can u guys tell me how to create a cpp program to print all the armstrong numbers within a given limit.?
that is for you to do mate , or else you'll fail your computer exam(most probably) if you can't make ven these simple programs .

Well here's the main logic:
1. extract each digit , be taking modulus from 10(i.e. num % 10) or string operators if you're usin java n treatin as string.
2. then square that digit
3. add all squares
4. check if result is same as original number
5. if yes then number is armstrong , else not

Hope it helped
__________________
There are 10 types of people in the world: those who understand binary and those who do not.
Zeeshan Quireshi is offline  
Old 14-08-2007, 09:15 PM   #4 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: c++ program

^^^ Armstrong is sum of cubes, not squares.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 14-08-2007, 09:47 PM   #5 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,905
Default Re: c++ program

and create a function which returns 1 if number is Armstrong & otherwise 0.
Use a for loop in main() to pass numbers one by one to that function & if it returns 1, then print that number as an Armstrong !!!
got it ??
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline  
Old 14-08-2007, 09:58 PM   #6 (permalink)
damn busy...
 
utsav's Avatar
 
Join Date: Sep 2006
Location: Jhansi/Meerut
Posts: 1,973
Default Re: c++ program

i can make it using while loop as it is for a given limit of numbers.

its a school assignment .ICSE or ISC .right
__________________
MSI GX660 with ATI 5870 ultimate gaming lappy
Dell Studio 15(1555)
1TB+1.5TB external|N86|ZTE Blade|5230|E63|EP-630|Soundmagic PL50|Sennheiser CXL 400|Meelec M11P+
www.techjunkiez.com
utsav is offline  
Old 14-08-2007, 10:57 PM   #7 (permalink)
Banned
 
slugger's Avatar
 
Join Date: May 2004
Location: Baudland
Posts: 2,430
Default Re: c++ program

d00ds let d thread starter show us wat hes done and den v cud go abt correctin it instead of just tellin him how 2 do it [code/alg/flow]

let us not encourage members who want 2 use d forum to get his/her hw done by some 1 else
slugger is offline  
Old 14-08-2007, 11:31 PM   #8 (permalink)
die blizzard die! D3?
 
The_Devil_Himself's Avatar
 
Join Date: Aug 2007
Location: Event horizon
Posts: 2,340
Default Re: c++ program

I think he is stuck somewhere.And dudes you know that programming skills increases most when you read and understands codes written by others.
I don't know c++(i have just started it) but I think following c code should work for you.Note that I haven't checked if its running or not but I think its ok(atleast the logic is ok).
ok here it is:

void main()
{
int n,i,p,r,sum=0;
printf("Enter the no.:\n");
scanf("%d",&n);
for(i=0;i<=n;i++)
{r=i;
while(r!=0)
{p=r%10;
r=r/10;
sum=sum+p*p*p;
}
if(sum==i)
printf("%d\t",sum);
sum=0;
}
getch();
clrscr();
}





CHECKED,IT'S WORKING
__________________
Stealing your women and horses since 1843.

Last edited by The_Devil_Himself; 14-08-2007 at 11:36 PM.
The_Devil_Himself is offline  
Old 15-08-2007, 12:28 AM   #9 (permalink)
Broken In
 
Join Date: Apr 2005
Posts: 133
Default Re: c++ program

he wanted it in c++....these days they dont teach c before teaching c++...so I think u shud explain the printf scanf commands or use cin cout....coz i too dont know the printf scanf commands
__________________
Abhishek Bhattacharya
abhishek_del is offline  
Old 15-08-2007, 06:50 AM   #10 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,905
Default Re: c++ program

@ The_Devil_Himself

U should NOT told him the code. But u did !!! huh...
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline  
Old 15-08-2007, 08:12 PM   #11 (permalink)
C# Be Sharp !
 
Zeeshan Quireshi's Avatar
 
Join Date: Jun 2006
Location: Toronto
Posts: 1,805
Default Re: c++ program

@ The_Devil_Himself

Dud that's C not C++
__________________
There are 10 types of people in the world: those who understand binary and those who do not.
Zeeshan Quireshi is offline  
Old 15-08-2007, 08:40 PM   #12 (permalink)
die blizzard die! D3?
 
The_Devil_Himself's Avatar
 
Join Date: Aug 2007
Location: Event horizon
Posts: 2,340
Default Re: c++ program

Quote:
Originally Posted by Zeeshan Quireshi

Dud that's C not C++
Dude please read the full post first.I SAID I don't know c++ yet cos I have just started using it but I know c and I guess the logic is the same.
__________________
Stealing your women and horses since 1843.
The_Devil_Himself is offline  
Old 16-08-2007, 03:23 PM   #13 (permalink)
Pee into the Wind...
 
shady_inc's Avatar
 
Join Date: May 2007
Location: Mumbai
Posts: 782
Default Re: c++ program

Quote:
Originally Posted by Sykora
^^^ Armstrong is sum of cubes, not squares.
Nope armstrong nos. are the ones in which the sum of each individual digit in a no. raised to the no. of digits equals the original no.So for three digit no.,it will be sum of cubes.....For a two digit no.,it will be sum of squares.....

Every single digit no. except zero is armstorng no.Hava look here. for more info.
__________________
Life is as complicated as you say it is.
shady_inc is offline  
Old 16-08-2007, 04:11 PM   #14 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: c++ program

According to http://mathworld.wolfram.com/NarcissisticNumber.html , shady_inc is right.
mehulved is offline  
Old 16-08-2007, 07:01 PM   #15 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: c++ program

I guess I never got interested in them enough to go past 999
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 16-08-2007, 07:45 PM   #16 (permalink)
C# Be Sharp !
 
Zeeshan Quireshi's Avatar
 
Join Date: Jun 2006
Location: Toronto
Posts: 1,805
Default Re: c++ program

Quote:
Originally Posted by The_Devil_Himself
Dude please read the full post first.I SAID I don't know c++ yet cos I have just started using it but I know c and I guess the logic is the same.
That's why i informed you mate , so u know what is C++ and what is C , no harm intended .
__________________
There are 10 types of people in the world: those who understand binary and those who do not.
Zeeshan Quireshi is offline  
Old 16-08-2007, 08:11 PM   #17 (permalink)
>:)I-):(|)8-X
 
Charan's Avatar
 
Join Date: Sep 2004
Location: ಬೆಂಗಳೂರು (Bengaluru)
Posts: 3,512
Default Re: c++ program

That guy "sai_cool" posted this question and never came back

Quote:
Time Posted : 14-08-2007 08:29 PM
Last Activity: 14-08-2007 08:31 PM
__________________
i5 2400 | DH67BL | G.Skill Ripjaw 4 GB | FSP SAGA II 500W | CM 430 Black Elite | MSI R6850 Cyclone PE/OC | XBox 360 Controller | 21.5" Samsung Sync Master 2233 | 4 Mbps UL
Charan is online now  
Old 16-08-2007, 09:03 PM   #18 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,905
Default Re: c++ program

^^ U should say "Not logged in" bcoz he may be in Guests
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline  
Old 19-08-2007, 01:03 AM   #19 (permalink)
die blizzard die! D3?
 
The_Devil_Himself's Avatar
 
Join Date: Aug 2007
Location: Event horizon
Posts: 2,340
Default Re: c++ program

Quote:
Originally Posted by shady_inc
Nope armstrong nos. are the ones in which the sum of each individual digit in a no. raised to the no. of digits equals the original no.So for three digit no.,it will be sum of cubes.....For a two digit no.,it will be sum of squares.....

Every single digit no. except zero is armstorng no.Hava look here. for more info.
Thanks buddy I didn't know this.But still the code can be used with slight modifications.

Anyways I prefer fibonacci series over armstrong series....lols
__________________
Stealing your women and horses since 1843.
The_Devil_Himself is offline  
Closed Thread

Bookmarks

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
which program used gramesh QnA (read only) 6 20-04-2007 09:29 PM
program? rounit Software Q&A 6 10-04-2007 10:54 PM
program to run vb shivi4 QnA (read only) 2 24-06-2005 10:43 AM
new program in 'close program menu' list and more....... vishakadatta QnA (read only) 2 12-04-2005 11:33 PM
C++ Program Q. shwetanshu Programming 5 09-02-2005 01:50 PM


All times are GMT +5.5. The time now is 02:13 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2