473,749 Members | 2,350 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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
10 4859
weaknessforcats
9,208 Recognized Expert Moderator Expert
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 New Member
i know that is irrational but i need formula for a program to do it in c++
Aug 4 '14 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
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 Recognized Expert Top Contributor
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 Recognized Expert Top Contributor
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 Recognized Expert Moderator Expert
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 Recognized Expert Top Contributor
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 Recognized Expert Moderator Expert
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 Recognized Expert Top Contributor
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

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

Similar topics

4
8691
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 together and the square root of the product is returned and displayed for the user. The function should return a double. Hint: If you multiply an integer by 1.0 the result will be a double. For example:
2
3190
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
3144
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 a pseudorandom number generator. So, rather than calculate the square root to try to get a particular precision answer, you would calculate it to x number of bits. This particular function takes a radicand and the number of iterations as...
9
1757
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 program starts. I was trying to use number pi, but to calculate 100 million decimal places of number pi would take forever and no one would want to wait that long. On the other hand I can't afford to include the whole 100 million dec. places...
32
4994
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 Series? Is there any other way of doing it rather than using series? Thank you, Priyam
4
8491
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 simple task but my mind suddenly got stuck. I am trying to implement a square root function as a practice. I am able to code for the perfect square
10
13636
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 i go to print out the answer its rounding instead of giving me the answer i need... any help?? double num1, num2, the_root; cout<< "Enter number to have square root taken of it\n"; cin>> num1; cout<< "Enter number for how...
4
8095
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 involving lot of matrices. At one point I need to calculate the square root of a matrix e.g. A which contains non-zero off-diagonal elements. I searched for a lot of info on net but no algorithm worked. My best bet for finding square root was to find...
3
4538
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 root? square(x, y){ if((x*x) >= y){ //not a square root return false; }
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9566
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9333
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6800
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.