Question

USING C++: Write a function that will print out all the factors of a given positive...

USING C++:

Write a function that will print out all the factors of a given positive integer N. The factors of N are all the numbers that N is divisible by (i.e., x is a factor of N if N/x has remainder 0). The function prototype is provided below.

E.g.  factors(12) will print out 1, 2, 3, 4, 6, 12.
void factors(int);
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code in c++ is:

#include<iostream>
using namespace std;
int main()
{
   int n;
   cout<<"Enter the number whose factors are to be printed: ";
   cin>>n;
   void factors(int);
   factors(n);
   return 0;
}
void factors(int n)
{
   cout<<"Factors are: ";
   for(int i=1;i<=n;i++)
   {
       if(n%i==0)
           cout<<i<<" ";
   }
   cout<<"\n";
}

Snapshot of code(for indentation reference):

Snapshot of output:

Add a comment
Know the answer?
Add Answer to:
USING C++: Write a function that will print out all the factors of a given positive...
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
  • USING C++: Write a function that given a 2D dynamic array of integers, will return the...

    USING C++: Write a function that given a 2D dynamic array of integers, will return the number of elements whose absolute value is smaller than a given value x. The function should take as arguments (in this order): a pointer to the array (i.e., 2D dynamic array) the number of rows the number of columns the given value The function should return the number of elements smaller in absolute value than epsilon E.g. if A={{0.2, -0.1, 3.4},{4.4, 0, -2}} and...

  • Please solve it by Python 3 Write a program that asks the user for a positive...

    Please solve it by Python 3 Write a program that asks the user for a positive integer limit and prints a table to visualize all factors of each integer ranging from 1 to limit. A factor i of a number n is an integer which divides n evenly (i.e. without remainder). For example, 4 and 5 are factors of 20, but 6 is not. Each row represents an integer between 1 and 20. The first row represents the number 1,...

  • Write C++ statements that will print out how many of the elements in array numbers are...

    Write C++ statements that will print out how many of the elements in array numbers are divisible by 3. Given array filled with values: int numbers[12]; TTT Arial • 3(121) #T.EE Pathp Words:0

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

  • Write a Java Program to find the sum of all factors of a given positive integer....

    Write a Java Program to find the sum of all factors of a given positive integer. Make sure to satisfy and show different results for any inputs, for example, 0, negative numbers, odd numbers, prime numbers, huge integers, etc. For example, if the integer is 12: Then the factors are: 1, 2, 3, 4, 6, 12 ; And their sum is: 28.

  • 2) Given an array of n nonzero real numbers a[0]…a[n-1], write a function to partition the...

    2) Given an array of n nonzero real numbers a[0]…a[n-1], write a function to partition the array (not sort) so that all its negative elements come before all its positive elements. Your algorithm should have O(n) time complexity. The function prototype is void negpospartition(float a[], int n) Please use C language

  • Write a while loop that prints all positive numbers that are divisible by 10 and less...

    Write a while loop that prints all positive numbers that are divisible by 10 and less than a given number n. For example, if n is 100, print 10 20 30 40 50 60 70 80 90. import java.util.Scanner; public class PositiveLess {    public static void main(String[] args) {        Scanner in = new Scanner(System.in);        System.out.print("n: ");        int n = in.nextInt();        ...        while (...)        {           ...

  • How to solve it using Python? 5. Write a function called no_squares which takes an input...

    How to solve it using Python? 5. Write a function called no_squares which takes an input parameter N, a positive integer, and returns: 1 if N is not divisible by a square and has an even number of prime factors -1 if N is not divisible by a square and has an odd number of prime factors 0 if N is divisible by a square For example, no-squares (10) returns 1 (since 10 = 2x5), no-squares (30) returns-1 (since 30...

  • Q1) Write a C function that allows the user to initialize a Tic-Tac-Toe board. The board...

    Q1) Write a C function that allows the user to initialize a Tic-Tac-Toe board. The board is a 2D array of size 3x3. The function will set an id for each cell of the board starting from 1 and stop at 9. The function prototype is ​void​​ ​​InitializeBoard​​(​​int​​ m, ​​int​​ n , ​​char​​ board[][n]) void​​ ​​InitializeBoard​​(​​int​​ m, ​​int​​ n , ​​char​​ board[][n])​​{ ​​int​​ c =​​1​​; ​ for​​(​​int​​ i =​​0​​; i<m; i++){ ​​ for​​(​​int​​ j=​​0​​; j< n; j++){ board[i][j] = c+​​'0'​​;...

  • A positive integer n is “perfect” if the sum of its positive factors, excluding itself, equals...

    A positive integer n is “perfect” if the sum of its positive factors, excluding itself, equals n.  Write a perfect function in Haskell that takes a single integer argument and returns the list of all perfect numbers up to that argument. Report all of the perfect numbers up to 1000 (i.e. call 1000)

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