Question

Please paste your code and a screenshot of your output!

1. An integer n is divisible by 9 if the sum of its digits is divisible by 9. Develop a program to determine whether or not the following numbers are divisible by 9: n= 154368 n 621594 n-123456 2. A number is said to be perfect if the sum of its divisors (except for itself) is equal to itself. For example, 6 is a perfect number because the sum of its divisors (1 + 2 + 3) is 6. The number 8 is said to be deficient because the sum of its divisors (1 + 2 + 4) is only 7. The number 12 is said to be abundant because the sum of its divisors (1 + 2+ 3 + 4 + 6) is 16. Write a program that lists the factors of the numbers between 1 and 100 and classifies each number as perfect, deficient, or abundant. What to submit: Submit your .cpp file and screenshot of your sample Input and output.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution #include <iostream> using namespace std; int main() //declare the number num as integer variable int num //initializCopyable Code:

1.

#include <iostream>

using namespace std;

int main()

{

    //declare the number num as integer variable

    int num;

    //initializes the digit sum ds is 0

    int ds= 0;

    //declare the variable for digit d

    int d;

    //get the number

    cout<<"Enter number: ";

    cin>>num;

    //initializes the given num to res

    int res = num;

    //using loop add the digit of one by one number

    while (num)

    {

        d = num % 10;

        ds += d;

        num /= 10;

  }

    //check the given digit sum is divisible by 9 or not

    if (ds % 9)

        cout<<res<<" is not divisible by 9";

    else

        cout<<res<<" is divisible by 9";

  

    return 0;

}


2.

#include <iostream>

using namespace std;

int main()

{

    //declare the variable

    int num,i,sum=0;

    //get the number

    cout<<"Enter a number: ";

    cin>>num;

    //print the factors ofgiven input number

    cout<<"Factors of "<<num<<" are: ";

    //using loop, find the factor and sum

    for(i=1;i<num;++i)

    {

        if(num%i==0)

        {

           cout<<" "<<i<<" ";

           sum=sum+i;

        }

    }

    cout<<"\n";

    //check if the sum is equal to given number, then it is perfect number

    if(sum==num)

    {

     cout<<"The given number "<<num<<" is a perfect number";

    }

    //otherwise

    else

    {

        //check if the sum is less than to given number, then it is deficient number

        if(sum<num)

        {

          cout<<"The given number "<<num<<" is a deficient number";

        }

        //otherwise, it is abundant number

        else

        {

          cout<<"The given number "<<num<<" is an abundant number";

        }

    }

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Please paste your code and a screenshot of your output! 1. An integer n is divisible...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C Programming Write a C program that asks the user for a positive number n (n...

    C Programming Write a C program that asks the user for a positive number n (n ≥ 1) then, the program displays all the perfect numbers up to (including) n. A number n is said to be a perfect number if the sum of all its positive divisors (excluding itself) equals n. For example, the divisors of 6 (excluding 6 itself) are 1,2 and 3, and their sum equals 6, thus, 6 is a perfect number. Display the numbers with...

  • Please circle all the answers and I will rate you thumbs up ? 43: Problem 5...

    Please circle all the answers and I will rate you thumbs up ? 43: Problem 5 Previous Problem Problem List Next Problem (1 point) The proper divisors of a natural number n are those factors of n that are less than n. For example, the proper divisors of 10 are 1, 2 and 5. If the sum of the proper divisors of n is larger than n then n is said to be abundant. If the sum is less than...

  • An integer is said to be a perfect number if the sum of its divisors, including...

    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...

  • This code should be in C please!! Your file should meet the following criteria: • Function...

    This code should be in C please!! Your file should meet the following criteria: • Function prototype and implementation for a calculateDivisors function that takes in an integer parameter, calculates the sum of its divisors, and returns that sum (as an integer value) • A structure that represents what is represented on each line of output, e.g., o Line number o Sum of the divisors for that line number o Character array containing “Perfect”, “Deficient”, or “Abundant” • Pointer declared...

  • Code in C An integer is divisible by 9 if the sum of its digits is...

    Code in C An integer is divisible by 9 if the sum of its digits is divisibleExample output: by 9. Develop a program which will call UDF: int get input(); to prompt the user for an integer and return this user input to main() Call UDF: Enter an integer: 5463 3 4 5 5463 is divisible by 9 void display int val); to display each digit of the integer starting with the rightmost digit. Your program should also determine whether...

  • Please Write the task in c++ Task A perfect number is an integer that is equal...

    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...

  • A positive integer is said to be a perfect number if it equals the sum of...

    A positive integer is said to be a perfect number if it equals the sum of its positive divisors (excluding the number itself). As an example, 6 is aperfect number because its divisors, 1, 2, and 3 sum up to 6. The first four perfect numbers are 6, 28, 496, 8128. Write a C program that asks the user to enter a number and checks if the number is perfect. Your program should run interactively until the user quits. Try...

  • A perfect number is a positive integer that equals the sum of all of its divisors...

    A perfect number is a positive integer that equals the sum of all of its divisors (including the divisor 1 but excluding the number itself). For example 6, 28 and 496 are perfect numbers because 6=1+2+3 28 1 + 2 + 4 + 7 + 14 496 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248 Write a program to read a positive integer value, N, and find the smallest perfect number...

  • A perfect number is a positive integer that is equal to the sum of its (proper)...

    A perfect number is a positive integer that is equal to the sum of its (proper) positive divisors, including 1 but excluding itself. A divisor of a number is one which divides the number evenly (i.e., without a remainder). For example, consider number 6. Its divisors are 1, 2, 3, and 6. Since we do not include number itself, we only have 1, 2, and 3. Because the sum of these divisors of 6 is 6, i.e., 1 + 2...

  • Write a Python program to print all Perfect numbers between 1 to n. (Use any loop...

    Write a Python program to print all Perfect numbers between 1 to n. (Use any loop you want) Perfect number is a positive integer which is equal to the sum of its proper positive divisors. Proper divisors of 6 are 1, 2, 3. Sum of its proper divisors = 1 + 2 + 3 = 6. Hence 6 is a perfect number. *** proper divisor means the remainder will be 0 when divided by that number. Sample Input: n =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT