Write a program to accept a number from user and check if it's an amicable number or not using functions.
Answers
Explanation:
// CPP program to check if two numbers are
// Amicable or not.
#include <bits/stdc++.h>
using namespace std;
// Function to calculate sum of all
// proper divisors of a given number
int divSum(int n)
{
// Sum of divisors
int result = 0;
// find all divisors which divides 'num'
for (int i = 2; i <= sqrt(n); i++)
{
// if 'i' is divisor of 'n'
if (n % i == 0)
{
// if both divisors are same
// then add it once else add
// both
if (i == (n / i))
result += i;
else
result += (i + n/i);
}
}
// Add 1 and n to result as above loop
// considers proper divisors greater
// than 1.
return (result + 1);
}
// Returns true if x and y are Amicable
// else false.
bool areAmicable(int x, int y)
{
if (divSum(x) != y)
return false;
return (divSum(y) == x);
}
int main() {
int x = 220, y = 284;
if (areAmicable(x, y))
cout << "Yes";
else
cout << "No";
return 0;
}
Answer:
i can't understand what u r asking but I u r asking about how to write a no. in excel sheet cell then simply place a space between the no.