[ create a new paste ] login | about

Link: http://codepad.org/h9v0geus    [ raw code | output | fork ]

hmurcia - C++, pasted on Aug 17:
// Numeros amigos (usando funciones)
#include <iostream>
using namespace std;

bool amigos( int, int );
int sumDivisoresP( int );

int main()
{
    int Na, Nb;
    cout << "\n\nIngrese dos numeros enteros: ";
    Na=220; Nb=284;  //cin >> Na >> Nb;
    cout << "\n\n" << Na << " y " << Nb;
    if ( !amigos(Na, Nb) )
        cout << " no";
    cout << " son numeros amigos.\n\n";
}

bool amigos( int X, int Y )
{
    return ( X==sumDivisoresP(Y) && Y==sumDivisoresP(X) );
}

int sumDivisoresP( int v )
{
    int d = v-1;

    int sum = 1;
    while(d>1)
    {
        if (v%d==0)
            sum += d;
        d--;
    }
    return sum;
}


Output:
1
2
3
4
5
6


Ingrese dos numeros enteros: 

220 y 284 son numeros amigos.



Create a new paste based on this one


Comments: