Knowee
Questions
Features
Study Tools

Anna is working on a program to find common factors of two unsigned integers. Design a program that:Takes two unsigned integers: n1 and n2, as input.Identifies and prints all common factors of these numbers.

Question

Anna is working on a program to find common factors of two unsigned integers. Design a program that:Takes two unsigned integers: n1 and n2, as input.Identifies and prints all common factors of these numbers.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple Python program that accomplishes this task:

def find_common_factors(n1, n2):
    # Create an empty list to store common factors
    common_factors = []

    # Loop from 1 to the smallest of the two numbers
    for i in range(1, min(n1, n2) + 1):
        # If both numbers are divisible by i, it is a common factor
        if n1 % i == 0 and n2 % i == 0:
            common_factors.append(i)

    # Print the common factors
    for factor in common_factors:
        print(factor)

# Test the function
find_common_factors(12, 18)

This program defines a function find_common_factors that takes two unsigned integers as input. It then loops from 1 to the smallest of the two numbers. For each number in this range, it checks if both input numbers are divisible by it. If they are, it adds the number to a list of common factors. Finally, it prints all the common factors.

This problem has been solved

Similar Questions

Write a program to find out the Highest Common Factor for given two numbers.

Single File Programming QuestionProblem StatementAkil is looking to develop a program that identifies all the factors of a positive integer. The program should accept an integer 'n' as input, and then output all of its factors, while also classifying them as either odd or even. This task should be accomplished using a for loop.For example, the factors of number 15 are calculated as follows:1 * 15 = 153 * 5 = 155 * 3 = 1515 * 1 = 151, 3, 5, and 15 are the factors of 15.Odd factors are 1, 3, 5, and 15. There are no even factors.Note: This question helps in clearing technical coding tests for service-based companies.Input format :The input consists of an integer n for which the factors need to be calculated.Output format :The first line prints "Factors: " followed by the factors for the given number as integers, separated by a space.The second line prints "Odd factors: " followed by the odd factors for the given number as integers, separated by a space.The third line prints "Even factors: " followed by the even factors for the given number as integers, separated by a space.If there are no even factors present, the third line prints "Even factors: Unavailable".Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:2 ≤ n ≤ 10000Sample test cases :Input 1 :10000Output 1 :Factors: 1 2 4 5 8 10 16 20 25 40 50 80 100 125 200 250 400 500 625 1000 1250 2000 2500 5000 10000 Odd factors: 1 5 25 125 625 Even factors: 2 4 8 10 16 20 40 50 80 100 200 250 400 500 1000 1250 2000 2500 5000 10000 Input 2 :15Output 2 :Factors: 1 3 5 15 Odd factors: 1 3 5 15 Even factors: UnavailableInput 3 :2Output 3 :Factors: 1 2 Odd factors: 1 Even factors: 2 Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case

Tony is exploring functions and needs your help. Write a program to assist Tony where he inputs an integer N. The program should display the factors of N and count how many digits N has. Help him with the program using call-by-reference.Function Specifications:To display factors - void factors(int ); To display digits - int count_digits(int *);Input format :The input consists of an integer N.Output format :The first line of output prints "Factors: " followed by the factors of N, separated by a space.The second line of output prints "Total digits: " followed by the total digits of N.

Single File Programming QuestionProblem StatementBeula is solving a mathematical problem and seeks your assistance in writing a program. She is particularly interested in finding numbers with exactly 9 factors. Help her by creating a program that takes an integer N as input and identifies numbers from 1 to N that have exactly 9 factors.Function Specifications:check_9_factors - Prints the integers that have exactly 9 divisors as well as the total number of such integers.Note: This question helps in clearing technical coding tests for companies like Infosys.Input format :The input consists of an integer N.Output format :The first line displays space-separated integers representing numbers from 1 to N that have exactly 9 factors.The second line displays a single integer representing the count of numbers with exactly 9 factors.Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:100 ≤ N ≤ 1500Sample test cases :Input 1 :100Output 1 :36 100 2Input 2 :150Output 2 :36 100 2Input 3 :1500Output 3 :36 100 196 225 256 441 484 676 1089 1156 1225 1444 12Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Problem StatementIn a mathematical exploration, Alex wants to find the greatest prime divisor of a given positive integer. Create a program that accomplishes this task where Alex has a positive integer, represented as a long long int. The program should find and display the greatest prime divisor of this integer.Write a program that displays the greatest prime divisor for various positive integers.Input format :The input consists of a long long integer n, representing the encryption number.Output format :The output prints the greatest prime divisor as a long long integer.Refer to the sample output for formatting specifications.Code constraints :In this scenario, the given test cases fall under the following constraints:1 ≤ n ≤ 100Sample test cases :Input 1 :2Output 1 :2Input 2 :100Output 2 :5Input 3 :35Output 3 :7

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.