C program to find Square Root of a Number. For calculate Square Root of a number we multiply number by 0.5 because square root of any number means power of 1/2 and 1/2=0.5. And one another method for this program is use sqrt function it is pre-defined in math.h header file. Jun 07, 2015 Whatever it may be I’ve faced this problem several times during executing my programs in the Dev C compiler. It generally happens when you install Dev C and try to compile a cpp file in Windows 8/8.1 or in Windows 10, a windows pops-up saying that g has stopped working.
![]() Dev C++ Sqrt Problems 1
In my code (shown below) I have a problem with 'sqrt'. (I'm a beginner in C++, started yesterday)
For some reason, I can't compile because 'sqrt' is having an error. (This project is testing each number to tell if it's prime or not. [I got this straight from a book: C++ Without Fear: Second Edition]) So yea, the error is: 'more than one instance of overloaded function 'sqrt' matches the argument list' Could someone please tell me how to fix this? CODE: #include <iostream> #include <cmath> using namespace std; int main(){ int n; //Number to test for prime-ness. int i; //Loop counter int is_prime = true; //Get a number from the keyboard. cout <<'Enter a number and press ENTER: '; cin >> n; //Test for prime by checking for divisibility //By all whole numbers from 2 to sqrt(n). i = 2.0; while (i <= sqrt(n)){ if (n % i 0); is_prime = false; // n is not prime i++; } //Print results if(is_prime) cout<<'Number is prime.' << endl; else cout <<'Number is not prime.' << endl; system('PAUSE'); return 0; } Comments are closed.
|
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |