C Code question Write a function that returns the sum of a n

C++ Code question

Write a function that returns the sum of a number’s proper divisors. The function’s prototype is int properDivisorSum(int number); Use the function properDivisor to write this function.

Solution

#include <iostream>
#include<stdlib.h>
using namespace std;
int properDivisorSum(int number)
{
   int sum=0;
   for(int i=1;i<=(number/2);i++)
   {
       if(number%i==0)
       {
           cout<<\"The ProperDivisible is :\"<<i<<endl;
           sum=sum+i;
          
       }
   }
   return sum;
}
int main()
{
   int n,s;
   cout<<\"Enter The Number for Finding ProperDivisor and the sum of proper divisor \ \";
   cin>>n;
   if(n<=1)
   {
       cout<<\"Please Enter The Valid Number\"<<endl;
       exit(1);
   }
   else
   {
       s=properDivisorSum(n);
       cout<<\"The Sum Of The proper Divisor\'s is :\"<<s<<endl;
   }
   return 0;
}

C++ Code question Write a function that returns the sum of a number’s proper divisors. The function’s prototype is int properDivisorSum(int number); Use the fun

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site