473,585 Members | 2,596 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

perfect square root

10 New Member
i need help mto do this question i have no clue on how to dis dis question

Write a program that checks whether the number entered by the user is a perfect square or not.
pls help

and does anybody know where i could get help on c++
Dec 18 '07 #1
12 20743
sicarie
4,677 Recognized Expert Moderator Specialist
We can help you with C++.

Do you know how to find if a number is a perfect square root by hand?
Dec 19 '07 #2
Thana1995
10 New Member
i think it is sqrt but i'm really new to dis stuff
Jan 1 '08 #3
oler1s
671 Recognized Expert Contributor
What is what sqrt?

It's 1900. No computers exist in the world. You are in a room with s sheet of paper and a number and its square root on it. How do you know if the number is a perfect square?

Having trouble thinking about it so abstractly? Let me give you four examples.

Example 1: 36 and 6.
Example 2: 30 5.47722558
Example 3: 25 and 5
Example 4: 24 and 4.89897949

So. How do you know if a number is a perfect square?
Jan 1 '08 #4
Thana1995
10 New Member
if it is a whole number then it is perfect square
but if it is a decimal then it is not a perfect square
Jan 1 '08 #5
oler1s
671 Recognized Expert Contributor
Ok, now look at the concept of an int in C++. An integer (which corresponds to its mathematical equivalent). 5 is an integer. 5.5 is not.

So in my example, 36 has a square of 6. This fits into an integer. 6 squared is 36.
30 has a square root of 5.48. What happens when you put it into an integer? Well, the five part works out. The decimal portion gets discarded. So in integer arithmetic, 30 has a square root of 5. And the square of 5 is 25. Whoops. 25 and 30 are not equal.

Do you see how to write the code now? If the code looks confusing, write down the logic in plain english first.
Jan 1 '08 #6
Andr3w
42 New Member
Well, there is another way to do that. You could use modf and break the fraction in 2 pieces, thus saving a multiplication. Now in order to get the perfect square you could just check if the decimal part was equal to zero. The following code shows that

Expand|Select|Wrap|Line Numbers
  1. ...deleted...
  2.  
Hope this helped ;)
Jan 2 '08 #7
Thana1995
10 New Member
int number
cout<<"Please enter a number."<<'\n';
cin>>number
while number=sqrt(num ber)


that all i know
Jan 9 '08 #8
oler1s
671 Recognized Expert Contributor
That's not complete compilable code. Those aren't statements anyway, as you are missing semicolons. Your while loop...well, I don't see how a while loop is useful, but your while loop statement is nonsensical. And you forgot CODE tags. Not that it matters since what you posted is utter nonsense.

All forgiveable, as you are a complete beginner. But I see no effort to think on your part. Break it down into sections. Start with a code skeleton. You need a main. You probably want the iostream header for I/O. You probably want cmath for the sqrt function.

Have you covered if statements? You seem completely unfamiliar with the syntax. Fix that problem. Look through your book. Or go online, like cprogramming.co m and cplusplus.com and look at the syntax again.

If you find it difficult to write code directly, write PLAIN ENGLISH statements, detailing the steps the program must take. Then try and convert them into code.
Jan 9 '08 #9
Thana1995
10 New Member
please enter a number
input number
square root number
if number has decimal output " it is not a perfect square"
if number has no decimal output"perfect square"
Jan 19 '08 #10

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

Similar topics

4
8679
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...
2
3182
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
3134
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...
32
4968
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
8463
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
4
8098
by: The 1 | last post by:
Q-1 Can sm1 suggest a program to check whether a given no is perfect square or not?? Q-2 Also sm1 suggest a program to check whether a given no is perfect power or not?? * PEfect power is a no which can be expressed some power of a any noo. Its better if it is very efficient!
10
13624
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<<...
4
8082
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...
0
7904
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...
0
8195
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. ...
1
7947
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...
0
8209
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6596
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5386
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3831
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3856
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2340
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

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.