C++ program :-
#include <iostream>
using namespace std;
void printdivisors(int
num){
for (int i=1;i<num;i++)
if (num%i==0)
cout<<i<<" ";
}
int sumdivisors(int
num){
int sum=0;
for (int i=1;i<num;i++)
if (num%i==0)
sum=sum+i;
return sum;
}
void allperfects(int
low_range, int high_range)
{
for(int i=low_range;i<=high_range;i++)
{
int sum=0;
for (int j = 1; j <= (i - 1); j++)
{
int rem = i % j;
if (rem == 0)
{
sum = sum + j;
}
}
if (sum == i)
cout<<i<<" ";
}
}
int main()
{
cout<<"Print divisors :"<<endl;
printdivisors(6);
cout<<endl<<"The perfect numbers :"<<endl;
allperfects(1,20);
cout<<endl<<"The sum of divisors
:"<<sumdivisors(6)<<endl;
}
Output :-
C++ 2. (a) Write a function, printdixisors, that takes a single integer parameter and prints all...
Write a function, sumdivisors, that takes a single integer parameter and returns the sum of all the divisors of the parameter (including 1). So sumdivisors(6) will return 6 as 1+2+3=6. Note you may use a wrapper function or default parameters.
Write a function that takes as an input parameter an integer that will represent the length of the array and a second integer that represents the range of numbers the random number should generate (in other words, if the number is 50, the random number generator should generate numbers between 0 and 49 including 49. The function then sorts the list by traversing the list, locating the smallest number, and printing out that smallest number, then replacing that number in...
Write a recursive function named arithmeticSum that takes a positive integer parameter n and returns the sum of the integer numbers from 1 to n Please write in C++
For C++: A perfect number has these properties 1) positive integer 2) the sum of its proper divisors is the number itself 6 and 28 are perfect numbers Write two functions that return true if its value parameter is a perfect number and false if its value parameter is not a perfect numbers. The two function look like bool isPerfect(int) and void isPerfect(int, bool&) If you want more perfect number you find them on the Internet.
Write a function that takes an array of C-strings as a parameter and the number of elements currently stored in the array, and returns a single C-string pointer that is the concatenation of all C-strings in the array. Note: The function must take 2 parameters and return "char *". Any other ways will cause some deduction of points.
Please Write the task in c++ Task A perfect number is an integer that is equal to the sum of its divisors (where 1 is considered a divisor). For example, 6 is perfect because its divisors are 1, 2, and 3, and 1 + 2 + 3 is 6. Similarly, 28 is perfect because it equals 1 + 2 + 4 + 7 + 14. A quite good number is an integer whose badness—the size of the difference between the...
Using the C Programming Language: An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6 = 1 + 2 + 3. Write a function perfect that determines if parameter number is a perfect number. Use this function in a program that determines and prints all the perfect numbers between 1 and 1000. Print the factors of each...
it should be written in c or c++ program Question 1 (25 points) An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6 -1 + 2 + 3. Write a function perfect that determines if parameter number is a perfect number. Use this function in a program that determines and prints all the perfect numbers between 1...
An integer is said to be a perfect number if the sum of its divisors, including 1(but not the number itself), is equal to the number. For example, 6 is a perfect number because 6 = 1+2+3. A) Write a function numPerfect( number ) that returns true when the number is a perfect number, false when it is not. B) Write a C# console program that calls the function in A) to determine and print all the perfect numbers...
Write a function that takes an integer input n as a parameter and after it calculates the sum of 1+2+3+...+n, it returns the value to the main program. For example, if n=4, the output of the sum will be 10.