GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Oct-2004, 23:51
quasimof quasimof is offline
New Member
 
Join Date: Oct 2004
Posts: 4
quasimof is on a distinguished road

getting pWned by this code


I have two assignments for my computer science class that am too dumb to figure out and am hoping one of you code h4x0rz can help me out.


1.
Two numbers are called amicable if the proper divisors of one sums to the other.

For example, the pair 220 and 284 are amicable numbers:

The proper divisors of 220 are: 1+2+4+5+10+11+20+22+44+55+110 = 284

The proper divisors of 284 are:
1+2+4+71+142 = 220

Write a program which accepts two integers and determines whether or not the integers form an amicable pair.

Allow the user to repeat the calculation as many times as he/she wishes. (see sample run).


Enter two numbers: 220 284
220 and 284 are amicable

Run again? Y or y for Yes: y

Enter two numbers: 1000 1024
1000 and 1024 are not amicable

Run again? Y or y for Yes: n
Bye.

this is my code so far:

CPP / C++ / C Code:
==========================================================

#include<iostream>
using namespace std;
int main(void)
{
	int choice='y';

	while((choice == ' y' )||(choice == ' Y ' ))
	{

	int n1, n2;
	cout<<"enter 2 numbers: "<<endl;
	cin>>n1>>n2;

	int i;
	int amicable;


	for(i=1; i<n1; i++)
	{
		amicable=n1/i;
	}
		
	if(n1%i==0)
	{
		while(amicable<=(n1/2))
		{
		amicable=amicable+amicable;
		cout<<"amicable"<<amicable<<endl;
	}
	if(amicable==n2)
	{
		cout<<n1<<" and "<<n2<<" are amicable"<<endl;
	}
	else
	{
		cout<<n1<<" and "<<n2<<" are not amicable"<<endl;
	}

	}
	}

		
	return 0;
}

//when i run it it says everything is not amicable.  

===========================================================

2.
Write a program to test for insipid integers between 1 and 99.
Your program will prompt the user for a number from 1 to 99. It
will then print out the sequence as described above and tell whether the number is insipid or not.

For example, if you begin with 25 the sequence is

25 29 (since 29 = 22 + 52) 85 (since 85 = 22 + 92) 89 (89 = 82 + 52) etc.

Notes:

a) if any term in the sequence equals 1, then all successive terms are 1
b)if any term in the sequence equals 58, then the sequence cycles:
…, 58, 89, 145, 42, 20, 4, 16, 37, 58, 89, 145…..

It is known that either condition a or b MUST occur.

An integer N0 is called insipid if condition (a) occurs.

Sample Run :

number : 2
The sequence starting at 2 is : 2 4 16 37 58
Not insipid

Run again (Y for yes) Y

number : 13
The sequence starting at 13 is : 13 10 1
insipid

Run again (Y for yes) N



Note: You will need to separate the digits of a number of at most three digits. Use / and %. The largest number you will have is a three digit number.

CPP / C++ / C Code:
=============================================================


#include<iostream>
#include<cmath>
using namespace std;
int main(void)
{
	double n1=0;
	double n2=0;
	double sequence;
	
	cout<<"number: ";
	cin>>n1>>n2;

		do
		{
			n1=pow(n1, 2);
			n2=pow(n2, 2);
			sequence=n1+n2;
			cout<<sequence<<endl;
		}
		while(sequence<100);
		{
			sequence=sequence;
			cout<<sequence<<endl;
			sequence++;
		}
	
	return 0;
}


//as you can see i basically pulled this code out of my ***.  
//if you input 2 it only outputs 4, 16, 256, 256.
Last edited by LuciWiz : 21-Oct-2004 at 00:34. Reason: Please insert your C code between [c] [/c] tags
  #2  
Old 21-Oct-2004, 22:30
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,373
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
For the first program, try outputting all the 'proper' values as you arrive at them to see if you are calculating them properly.

For the second, I didn't read it close enough... I'll get back to it later if noone else responds,
__________________

The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
 
 

Recent GIDBlogInstall Adobe Flash - Without Administrator Rights by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Formatting C / C++ code WaltP C Programming Language 1 06-Jan-2008 23:59
very difficult code - program gaurav_sting C++ Forum 1 16-Jun-2004 00:59
Explain code in MS STL's binary_search rom C++ Forum 11 07-Mar-2004 20:11
something wrong with this code loon MySQL / PHP Forum 5 07-Jul-2003 05:55

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:14.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.