Ask your own question, for FREE!
Computer Science 9 Online
OpenStudy (anonymous):

Write C++ prgm to find the sqrt of a number using functions?

OpenStudy (anonymous):

Here it is : #include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int x; //Declare a variable. printf("Enter a number : "); // A small message scanf("%d", &x); //Get the value entered by the user. printf("SQRT = %f\n", sqrt(x)); // Use the predifined function sqrt(), // in the library math.h, and print out the result. system("pause"); } Good luck.

OpenStudy (anonymous):

#include<iostream> #include<cmath> #include<iomanip> int main() { cout<<fixed<<setprecision(2)<<endl; double number; cout<<"Enter the number i'll give you the square root : " cin>>number; cout<<"The square root is "<<sqrt(number)<<endl; return 0; }

OpenStudy (anonymous):

#include <iostream> using namespace std; void input(int &num); void find_sqrt(const int num,int &sqrt_no); void output(const int num,const int sqrt_no); int main () { int sqrt_no=1,num=1; input(num); find_sqrt(num,sqrt_no); output(num,sqrt_no); return 0; } void input(int &num) { cout<<"Please Enter Positive Integer: "; cin>>num; } void output(const int num,const int sqrt_no) { if(sqrt_no*sqrt_no==num) cout<<"Square Root is "<<sqrt_no<<endl; else cout<<"Square Root is Not found"<<endl; } void find_sqrt(const int num,int &sqrt_no) { for(sqrt_no=0;sqrt_no<=num/2;sqrt_no++) { if(sqrt_no*sqrt_no==num) break; } }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!