A positive integer is said to be square-free if none of its factors (greater tha
ID: 441010 • Letter: A
Question
A positive integer is said to be square-free if none of its factors (greater than 1) are themselves squares. For example, the positive integer 30 has factors 1, 2, 3, 5, 6, 10, 15, and 30. None of these factors (greater than 1) are themselves squares, and so 30 is square-free. For another example, the positive integer 36 has factors 1, 2, 3, 4, 9, 12, 18, and 36. Notice that 2 of these factors (greater than 1) are themselves squares: 4 (since 4 is 2 * 2) and 9 (since 9 is 3 * 3). Therefore, 36 is not square-free. An ordered pair of positive integers can be classified in one of four ways: ? If both of the integers in the pair are square-free, then this pair is HAPPY. ? If the first integer in the pair is square-free but the second one is not, then this pair is SLEEPY. ? If the second integer in the pair is square-free but the first one is not, then this pair is SNEEZY. ? If neither of the integers in the pair are square-fee, then this pair is GRUMPY. Write, compile, execute, and test a C++ program that asks the user to input an ordered pair of integers, each between 2 and 5000. Then, for each integer of the pair, it should display that integer's factors (greater than 1) that are themselves squares, and also display whether or not that integer is square-free. Finally, it should display whether this ordered pair of integers is HAPPY, SLEEPY, SNEEZY, or GRUMPY. If you havenExplanation / Answer
All you need to do is find the factors of the number given as input and count the number of square factors it has with the help of the code i am giving below. If the count is 0, then the number is square free, else it is not. #include #include void main() { int n,sqr=0; clrscr(); printf(" ENTER THE NO.:= "); scanf("%d",&n); sqr=n*n; printf(" SQUARE OF %d is %d .",n,sqr); getch(); } Cheers! Please rate :)Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.