Wolfram language (Mathmatica Programming) (a) Write a function which takes as in
ID: 3885347 • Letter: W
Question
Wolfram language (Mathmatica Programming)
(a) Write a function which takes as input a positive integer n and returns the sum of all proper divisors of n. Show how your function works for the following values of n : 2, 3, 4, 6, 30, 900.
(b) Using the function you wrote in (a) write a function perfectQ which takes as input a positive integer n and returns true if n is perfect and false if not. Note : proper divisors of n can not be greater than n/2. Use the function to find all perfect numbers n <= 1000.
Explanation / Answer
Program (a) :
#include <stdio.h>
int properDivisor(int n) /*function return a int type value and have an argument n that is a number passed by callingfunction */
{
int i,sum=0; //initially sum is initialize 0
if(n>=0) //condition is checked whether passed number is not a positive number
{
for(i=1;i<=n/2;i++)
{
if(n%i==0) //condition checking : if n is completely divided by i
sum += i; //if condition is true the value of sum will be updated sum = sum + 1;
}
}
else
{
printf("Error! Enter a positive number...");
}
return sum;
}
input: 2 output : 1
input: 3 output : 1
input: 4 output : 3
input: 6 output : 6
input: 30 output : 42
input: 900 output : 1921
Program (b):
public boolean perfectQ(int n)
{
int i;
i = properDivisor(n);
if(n == i)
return true;
else
return false;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.