473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

check the rational or irrational numbers after we take the square root

2
I tried to check the rational or irrational numbers after we take the square root. i dont get the formula. for eg. squareroot of 64 is 8 and it is rational. square root of 2 is irrational. how to check it in c++..
Aug 4 '14 #1

✓ answered by weaknessforcats

The rational number is the ratio of two integers. Without two integers there is no rational number. So a single integer, like 8, is not rational. However, you can say that the integer 8 can map to the rational 8/1. Since you can this for all integers, all integers can be converted to rational numbers of the form n/1.

A number with decimal places cannot map to an integer/1 so these are not rational numbers. Instead, these are real numbers. Real numbers are complex numbers but without an imaginary component.

If you calculate the square root of 8 you will get an integer value of 2 because 3 squared is 9, which is larger than 8. Then squaring your result 2x2 you get 4 which is not 8. Therefore, the square root of 8 is not rational.

To calculate the square root of, say 25, you start with 2 and square it (4). 4 is less then 25 so increment to 3 and square it. 9 is less then 25. Increment to 4. 4 squared is 16. Next is 5. 5 squared is 25 and is exactly equal to the original number 25. Therefore the square root of 25 is an integer represented by the rational number 5/1.

10 4825
weaknessforcats
9,208 Expert Mod 8TB
As I recall, a rational number is one integer divided by another. Like 2/3. There's no square root involved. Note that 2/3 is a rational number but 0.6666667 is not because it is not of the form x/y.

The divisor integer cannot be zero.

The square root of 2 is irrational because it cannot be represented by some x/y.

So, I'm not sure what you are doing. If your number is not of the form x/y then it is not rational.
Aug 4 '14 #2
Dashmi
2
i know that is irrational but i need formula for a program to do it in c++
Aug 4 '14 #3
weaknessforcats
9,208 Expert Mod 8TB
Calculate your square root using only integer variables. Then square your result and compare it to the original number. If the compare is true the number is rational.

Using integer variables, the square root of 2 is 1, which when squared does not equal 2. Therefore, the square root of 2 is irrational.

Please note that the square root of 64 is 8 but 8 is not a rational number because it is not of the form x/y. You would need to say 8/1 or 64/8 since either would be 8.
Aug 4 '14 #4
donbock
2,426 Expert 2GB
A floating point number (f) is typically represented by three integer values: significand (c), exponent (q), and the [implied] base (b), where f = c * (b^q). This implies that all representable floating point numbers are rational. For example, the square root of 2 is irrational, but the value returned by sqrt(2.) is rational.

Checking if the square of the sqrt() value matches the original integer only tells you if the square root is representable. While, all irrational numbers are unrepresentable, there are also unrepresentable rational numbers (for example, 1/3 -- when the base is two).

I don't know offhand how to predict which square roots are rational and which aren't. The first place I would look is to review the classical proof of the irrationality of the square root of two. Perhaps you can generalize the logic.
Aug 4 '14 #5
donbock
2,426 Expert 2GB
Do you need to assess the rationality of the square root of integers or of possibly nonintegral rational numbers?
Aug 4 '14 #6
weaknessforcats
9,208 Expert Mod 8TB
You can't use sqrt because it uses floating point. Floating point is not represented by x/y where x and y are integers. Due to rounding you will not be able to convert any floating point number to a ratio of two integers. You would need infinite decimal places.


Remember if you have the square root of 64 that would be 8. Presumably, the 8 is representing the infinite set of rational numbers that are multiples of 8. 8 is not rational itself but it can be mapped to 8/1 which is rational or to 16/2, etc.

Mapping the integer 8 to 8/1 and 9 to 9/1 just proves the unbounded set of integers is bounded by the set of rationals since there exists at least one rational number, like 22/7, that is not mappable to the integers.

What is this formula you are using?
Aug 4 '14 #7
donbock
2,426 Expert 2GB
I believe the OP wishes to write a program to determine whether the square root of some arbitrary input value is rational or irrational. It isn't clear to me yet if the input values can be any positive rational number or if they are restricted to positive integer values.

The hard part here is developing an algorithm from the relevant number theory. Writing a program to implement that algorithm will be relatively easy.

Hint: is the square root of a prime number (other than 1) rational or irrational?
Aug 5 '14 #8
weaknessforcats
9,208 Expert Mod 8TB
The rational number is the ratio of two integers. Without two integers there is no rational number. So a single integer, like 8, is not rational. However, you can say that the integer 8 can map to the rational 8/1. Since you can this for all integers, all integers can be converted to rational numbers of the form n/1.

A number with decimal places cannot map to an integer/1 so these are not rational numbers. Instead, these are real numbers. Real numbers are complex numbers but without an imaginary component.

If you calculate the square root of 8 you will get an integer value of 2 because 3 squared is 9, which is larger than 8. Then squaring your result 2x2 you get 4 which is not 8. Therefore, the square root of 8 is not rational.

To calculate the square root of, say 25, you start with 2 and square it (4). 4 is less then 25 so increment to 3 and square it. 9 is less then 25. Increment to 4. 4 squared is 16. Next is 5. 5 squared is 25 and is exactly equal to the original number 25. Therefore the square root of 25 is an integer represented by the rational number 5/1.
Aug 5 '14 #9
donbock
2,426 Expert 2GB
A number with decimal places can certainly be rational and so can its square root. For example, 16/9 (1.777..) is rational. Its square root is 4/3 (1.333...); and that is also rational.

Questions for the OP to consider:
If your input is limited to integers...
... If the square root of an integer is not also an integer, can it be rational?
If your input can be any rational number...
... Can the square root of a prime number (other than 1) be rational? (This is a special case of the previous question.)
... What is the Fundamental Theorem of Arithmetic?

Note: everything in this post refers to mathematics. Nothing in this post refers to computer programming.
Aug 5 '14 #10
Rabbit
12,516 Expert Mod 8TB
Square roots of positive whole numbers that are not perfect squares are always irrational numbers. (Source wikipedia article on square roots).

So the only thing you need to check is whether or not you have a perfect square.
Aug 5 '14 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: cplusplus | last post by:
Hello, I have newbie question. I'm stuck on this current assignment. Write a program that prompts the user for two integer values, passes the values to a function where they are multiplied...
2
by: Protoman | last post by:
Can you help me? For 4, my square root funct gives 4 instead of 2; here's the code: #include <iostream> #include <cstdlib> using namespace std; template<class T> T Abs(T Nbr) {
2
by: Clint Olsen | last post by:
Hello: I posted a thread on comp.programming awhile back asking about an algorithm I implemented on square root. The idea was to use the square root of a prime number as a convenient way to get...
9
by: Vjay77 | last post by:
I am working on the program where is necessary to calculate huge amount of numbers in always the same sequence. In other words, these number have to be calculated and saved into memory before the...
32
by: priyam.trivedi | last post by:
Hi! Could anyone tell me how to find the square root of a number without using the sqrt function. I did it by using Newton's Formula. How can it be done by using the Binomial Theorem/Taylor...
4
by: sathyashrayan | last post by:
(This is not a home work question) Dear group, I want a program to find one number between a set of natural number.A program to guess a number in between a Natural number set.This should be a...
10
by: socondc22 | last post by:
my program is trying to use the babylonian algorithm in order to find the square root... i have a number for the number to have the square root taken of and also a number to run the loop... Whenever...
4
by: krishnai888 | last post by:
I had already asked this question long back but no one has replied to me..I hope someone replies to me because its very important for me as I am doing my internship. I am currently writing a code...
3
by: game2d | last post by:
how to test if a num is a square root? ex: 9 is square root 3 is not square root ///////////////////////////////////////////// x = 0; //always start at 0 y = 101010; //is this a square...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.