need a help!!! for c++ Write a function that computes the sum of an integer, non
ID: 3602446 • Letter: N
Question
need a help!!! for c++
Write a function that computes the sum of an integer, non-zero, number's positive divisors. The function has one parameter, the integer number and returns one value, the integer sum. A number's divisors divide the number with remainder zero
if the function's parameter is 6 then the function returns 12 because 6's positive divisors are 1,2,3 and 6.
If the function's parameter is -5 then the function returns 6 because -5 's positive divisors are 1 and 5.
If the function's parameter is 5 then the function return 6 because 5's positive divisors are 1 and 5.
If the function's parameter is 28 then the function returns 56 because 28's positive divisors are 1, 2, 4, 7,14, and 28.
this is a example of this work!
#include <utility>
#include <iostream>
#include <random>
#include <string>
using namespace std;
void swap(int &a, int &b);
pair<int, int> swapByPair(int a, int b);
//int x = 13, y = 31; //global scope
namespace { //file scope
int x = 45, y = 54;
}
int main()
{
int x = 1, y = 2; //local scope
{
int x = 3, y = 5; //block local scope
cout << x << '/' << y << endl;
swap(x, y);
cout << x << '/' << y << endl;
}
cout << x << '/' << y << endl;
cout << ::x << '/' << ::y << endl;
{
int x = 3, y = 5;
cout << x << '/' << y << endl;
pair<int, int> old_pair = swapByPair(x, y);
cout <<
old_pair.first << '/' << old_pair.second << endl;
cout << ::x << '/' << ::y << endl;
}
system("pause");
return 0;
}
pair<int, int> swapByPair(int a, int b)
{
pair<int, int> new_pair(b, a);
return new_pair;
}
void swap(int &a, int &b)
{
int t = a;
a = b;
b = t;
}
Explanation / Answer
// Function that return sum of all positive divisor of n int sumOfDivisor(int n) { int sum = 0; // initialise sum with 0 n = abs(n); // if n is negative then make it positive for(int i = 1;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.