Question

In: Computer Science

Jojo just graduated and moved up to grade 4. Today is his first day in 4th...

Jojo just graduated and moved up to grade 4. Today is his first day in 4th grade. Unfortunately, the lessons are held online because of pandemic. So that the quality of learning remains good, Jojo’s teacher gives a hard task for 4th grader.

The first task is to find the prime factorization of a number. Prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. Prime factorization of a number is breaking a number down into the set of prime numbers which multiply together to result in the original number. Example below is the prime factorization of 1176.

. As a good friend of Jojo, help Jojo to solve the prime factorization task given by his teacher. Format Input There are T testcases. Each testcase contains an integer N which indicates the number to be factorized into prime factorization. Format Output Output T line with format “Case # X: ”, where X indicates the testcase number and then followed by the number prime factorization in ascending order of prime factors with the correct format.As a good friend of Jojo, help Jojo to solve the prime factorization task given by his teacher. Format Input There are T testcases. Each testcase contains an integer N which indicates the number to be factorized into prime factorization. Format Output Output T line with format “Case # X: ”, where X indicates the testcase number and then followed by the number prime factorization in ascending order of prime factors with the correct format.

Solutions

Expert Solution

So I am using C language to solve this problem. Since you have not mentioned which one to use.

The program is as follows:

#include<stdio.h>

#include<math.h>

void primeFactors(int n)

{

while(n%2==0)

{

printf("%d ", 2);

n=n/2;

}

for(int i = 3; i <= sqrt(n); i=i+2)

{

while(n%i==0)

{

printf("%d ", i);

n=n/i;

}

}

if(n>2)

{

printf("%d", n);

}

}

int main()

{

int n;

printf("Enter the Test Case : ");

scanf("%d", &n);

printf("Case 1: ");

primeFactors(n);

return 0;

}

  

Explanation for the above program:

First of all we have declared a function primeFactors(int n)

In this function we are going to write the logic of our problem statement

The logic is as follows:

1. We have to print the number of 2's that divide our number

- For this we have used while loop

2. We have to check whether the number divides by the prime numbers greater than 2

- For this we have used for loop, initially we say i is 3 and then we increament i by 2 until i is less than square root of our number

3. Again we use while loop so that as many times our number will divide by i that we will print

4. Now we divide our number by i and if our number is greater than 2 we print it

So, this was the logic

now we come to main function

take input as our test case

and print the result for our case


Related Solutions

Jojo just graduated and moved up to grade 4. Today is his first day in 4th...
Jojo just graduated and moved up to grade 4. Today is his first day in 4th grade. Unfortunately, the lessons are held online because of pandemic. So that the quality of learning remains good, Jojo’s teacher gives a hard task for 4th grader. The first task is to find the prime factorization of a number. Prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. Prime factorization of a number is...
Take Three Jojo just graduated and moved up to grade 4. Today is his first day...
Take Three Jojo just graduated and moved up to grade 4. Today is his first day in 4th grade. Unfortunately, the lessons are held online because of pandemic. So that the quality of learning remains good, Jojo’s teacher gives a hard task for 4th grader. After the 4th graders finished their first task which is prime factorization. Jojo’s teacher set up a game for the stundets. The game is very simple. Given N colored balls, each student has to take...
Take Three Jojo just graduated and moved up to grade 4. Today is his first day...
Take Three Jojo just graduated and moved up to grade 4. Today is his first day in 4th grade. Unfortunately, the lessons are held online because of pandemic. So that the quality of learning remains good, Jojo’s teacher gives a hard task for 4th grader. After the 4th graders finished their first task which is prime factorization. Jojo’s teacher set up a game for the stundets. The game is very simple. Given N colored balls, each student has to take...
C Programming Language Problem Title : 4th Grade Jojo just graduated and moved up to grade...
C Programming Language Problem Title : 4th Grade Jojo just graduated and moved up to grade 4. Today is his first day in 4th grade. Unfortunately, the lessons are held online because of pandemic. So that the quality of learning remains good, Jojo’s teacher gives a hard task for 4th grader. The first task is to find the prime factorization of a number. Prime number is a natural number greater than 1 that is not a product of two smaller...
C Programming Language Problem Title : Take Three Jojo just graduated and moved up to grade...
C Programming Language Problem Title : Take Three Jojo just graduated and moved up to grade 4. Today is his first day in 4th grade. Unfortunately, the lessons are held online because of the pandemic. So that the quality of learning remains good, Jojo's teacher gives a hard task for 4th grader. After the 4th graders finished their first task which is prime factorization. Jojo's teacher set up a game for the stundets. The game is very simple. Given N...
Burt is saving up for his retirement. Today is his 36th birthday. Burt first started saving...
Burt is saving up for his retirement. Today is his 36th birthday. Burt first started saving when he was 27 years old. On his 27th birthday, Burt made the first contribution to his retirement account when he deposited $2,000. Each year on his birthday, Burt has contributed another $2,000 to the account. The 10th (and last) of these contributions was made earlier today on his 36th birthday. The account has paid an effective annual rate of return of 5.4%. a)...
Burt Sbeez is saving up for his retirement. Today is his 40th birthday. Burt first started...
Burt Sbeez is saving up for his retirement. Today is his 40th birthday. Burt first started saving when he was just 25 years old. On his 25th birthday, Burt made the first contribution to his retirement account when he deposited $3,000. Each year on his birthday, Burt has contributed another $3,000 to the account. The 16th (and last) of these contributions is made today. The account has paid interest at the rate of 4.2% APR, compounded monthly. Burt wants to...
Grady​ Zebrowski, age​ 25, just graduated from​ college, accepted his first job with a ​$45 comma...
Grady​ Zebrowski, age​ 25, just graduated from​ college, accepted his first job with a ​$45 comma 000 ​salary, and is already looking forward to retirement in 40 years. He assumes a 3.5 percent inflation rate and plans to live in retirement for 20 years. He does not want to plan on any Social Security benefits. Assume Grady can earn a 6 percent rate of return on his investments prior to retirement and a 6 percent rate of return on his...
Grady​ Zebrowski, age​ 25, just graduated from​ college, accepted his first job with a $47,000 ​salary,...
Grady​ Zebrowski, age​ 25, just graduated from​ college, accepted his first job with a $47,000 ​salary, and is already looking forward to retirement in 40 years. He assumes a 2.1 percent inflation rate and plans to live in retirement for 20 years. He does not want to plan on any Social Security benefits. Assume Grady can earn a 9 percent rate of return on his investments prior to retirement and a 5 percent rate of return on his investments​ post-retirement...
Congratulations! You have just graduated from your University. Your first day on your new job involves...
Congratulations! You have just graduated from your University. Your first day on your new job involves a lot of paperwork including your decision to participate in the company 401K plan. First, should you participate? Second, describe the benefits of diversification if any including adding international stocks to your investment portfolio? You must include a full explanation to support your answer.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT