Question

In: Computer Science

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

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

Solutions

Expert Solution

Code:

#include <stdio.h>

void primeFactorization(int n, int p)
{
printf("Case #%d: ",p);
int c = 2;
while (c<n)
{
if (n%c == 0)
{
int e = 0;
while (n % c == 0)
{
n = n/c;
e++;
}
printf( "%d^%d",c,e);
if (n != 1)
printf( " * " );
}
c++;
}
if (n != 1)
printf( "%d^1\n",c);
else
printf("\n");
}

int main()
{
int T, N, i;
scanf("%d",&T);
for(i=0;i<T;i++)
{
scanf("%d",&N);
primeFactorization(N,(i+1));
}
}

Please refer to the screenshot of the code to understand the indentation of the code:

Output:

For any doubts or questions comment below.


Related Solutions

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...
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...
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...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
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 Title : Making wave In Physics, Mathematics, and related fields, a wave is...
C Programming Language Title : Making wave In Physics, Mathematics, and related fields, a wave is a disturbance of one of more fields such that the field values oscillate repeatedly about a stable equilibrium value. Waves are usually represented using mathematical functions of the form F (x, t), where x = position and t = time. Your task is to write a program that will visualize a given wave for exactly N seconds. You do not need to worry about...
Be sure to use only C for the Programming Language in this problem. Before we start...
Be sure to use only C for the Programming Language in this problem. Before we start this, it is imperative that you understand the words “define”, “declare” and “initialize” in context of programming. It's going to help you a lot when following the guidelines below. Let's begin! Define two different structures at the top of your program. be sure to define each structure with exactly three members (each member has to be a different datatype). You may set them up...
Problem: Make linkedList.h and linkList.c in Programming C language Project description This project will require students...
Problem: Make linkedList.h and linkList.c in Programming C language Project description This project will require students to generate a linked list of playing card based on data read from a file and to write out the end result to a file. linkedList.h Create a header file name linkedList Include the following C header files: stdio.h stdlib.h string.h Create the following macros: TRUE 1 FACES 13 SUITS 4 Add the following function prototypes: addCard displayCards readDataFile writeDataFile Add a typedef struct...
Please answer the problem below in C programming language: Create a pointer activity source file -...
Please answer the problem below in C programming language: Create a pointer activity source file - cptr2.c - that takes two arguments, a number from 1 to 3, and a string sentence(s). Create variables for a character, an integer, a string pointer. Based on integer value you will use that number of string pointers. The string variable is a string pointer that has not been allocated.    Define pointers to those variables types without any initialization of those points to the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT