Please write variables and program plan (pseudocode) of the C++ programming below:
#include <iostream>
#include <cmath>
using namespace std;
void divisors(int num);
int main ()
{
char repeat;
int num;
while (repeat !='n')
{
cout << "Enter a number:
";
cin >> num;
divisors(num);
cout << "Continue? (y or n):
";
cin >> repeat;
}
return 0;
}
void divisors(int num)
{
int divCount = 0, sum = 0;
cout << "Proper divisors: ";
for (int div = num-1; div > 1; div--)
{
if (num % div ==0)
{
cout <<
div << " ";
sum +=
div;
divCount++;
}
}
cout << endl;
cout << "Number of proper divisors = " <<
divCount << endl;
cout << "Sum of proper divisors = " << sum
<< endl;
}
This program is to find for a given number find the proper divisors, no.of proper divisiors, and sum of proper divisors
Pseudocode:
int main(){
declare num as int
declare repeat as char
while(repeat != 'n'){
take input from ther user = num
divisors(num)
}
}
void divisors(int num){
int divcount=0,sum=0;
for(int div = num-1;div>1,div--){
if(num % div == 0){
print div
sum += div;
divcount++;
}
}
print divcount
print sum
}
Variable used in this program
repeat as char
num as int
divcount as int
sum as int
div as int
Get Answers For Free
Most questions answered within 1 hours.