Question

In: Computer Science

Read a number N and print all its divisors.

Read a number N and print all its divisors.

Solutions

Expert Solution

The code is in C++.

#include <iostream>
using namespace std;

int main()
{
    
    int number;  //To store the Input from user
    
    //Message for the User to print the Number
    cout<<"Enter any number(+ve): ";
    cin>>number;   //Storing the User's input in number
    
    //Printing the Divisors of number
    cout<<"Divisors of "<<number<<" are: ";
    
    //For each i=1 that is less than equal to given number
    //Checking if that i can divide given number or not.
    //If i divides the number then its our Divisors, So print it.
    //Else check for next i.
    for (int i=1;i<=number;i++)
    {
        //Ch if i can divide number or not
        if (number%i==0) 
        {
            //Printing i as its a Divisors
            cout<<i<<" ";
        }
    }

    return 0;
}

Output Screenshot:

Code Screenshots:


Related Solutions

1.Divisors flow chart using modulo operator (%) to print out all the divisors of a user...
1.Divisors flow chart using modulo operator (%) to print out all the divisors of a user entered number. Your program should prompt the user to enter a positive number or 0 to end. Using a loop variable that starts at 1, your program should print out all the divisors of the entered number plus the number of printed divisors and their sum. For example: This program identifies and displays divisors of a given number. Developed as an IPC144 project. Enter...
Let τ (n) denote the number of positive divisors of n and σ(n) denote the sum...
Let τ (n) denote the number of positive divisors of n and σ(n) denote the sum of the positive divisors of n (as in the notes). (a) Evaluate τ (1500) and σ(8!). (b) Verify that τ (n) = τ (n + 1) = τ (n + 2) = τ (n + 3) holds for n = 3655 and 4503. (c) When n = 14, n = 206 and n = 957, show that σ(n) = σ(n + 1).
using Emulator Write an Assembly program that will produce all divisors for a 1-digit decimal number....
using Emulator Write an Assembly program that will produce all divisors for a 1-digit decimal number. For example, if the number is 6, then the outputs will be 1,2,3,6 which are the divisors of 6. show me the output
def annoying_valley(n): if n == 0: print() elif n == 1: print("*") elif n == 2:...
def annoying_valley(n): if n == 0: print() elif n == 1: print("*") elif n == 2: print("./") print("*") print(".\\") elif n == 3: print("../") print("./") print("*") print(".\\") print("..\\") elif n == 4: print(".../") annoying_valley(3) print("...\\") elif n == 5: print("..../") annoying_valley(4) print("....\\") elif n == 6: print("...../") annoying_valley(5) print(".....\\") else: print("." * (n - 1) + "/") annoying_valley(n - 1) print("." * (n - 1) + "\\") def annoying_int_sequence(n): if n == 0: return [] elif n == 1: return...
How to read and print all contents in a binary file using a Binary Search Tree...
How to read and print all contents in a binary file using a Binary Search Tree inorder traversal in C. Additionally, how to search using a Binary Search Tree to display the specific Athlete and his/her information. An example would be a sports record binary file that consist of name of athlete, height , weight, championships won. Athlete: Michael Jordan Height: 6’6” Weight : 205 lbs Championships won: 6 =================== Athlete: LeBron James Height: 6’8” Weight: 250 lbs Championships won:...
Let N(n) be the number of all partitions of [n] with no singleton blocks. And let...
Let N(n) be the number of all partitions of [n] with no singleton blocks. And let A(n) be the number of all partitions of [n] with at least one singleton block. Prove that for all n ≥ 1, N(n+1) = A(n). Hint: try to give (even an informal) bijective argument.
Use the Multiplication Rule to find the number of positive divisors of 20!. Include a procedure...
Use the Multiplication Rule to find the number of positive divisors of 20!. Include a procedure that “builds” such divisors
For all integers n > 2, show that the number of integer partitions of n in...
For all integers n > 2, show that the number of integer partitions of n in which each part is greater than one is given by p(n)-p(n-1), where p(n) is the number of integer partitions of n.
In C Write a program to read a one-dimensional array, print sum of all elements using...
In C Write a program to read a one-dimensional array, print sum of all elements using Dynamic Memory Allocation.
Prove that for all integers n ≥ 2, the number p(n) − p(n − 1) is...
Prove that for all integers n ≥ 2, the number p(n) − p(n − 1) is equal to the number of partitions of n in which the two largest parts are equal.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT