Sunday, June 14, 2020
Program to find square root
Write a C program to find square root of a given number using sqrt() funciton (This function is used to find square root of a given number). Now let's see, how to use this sqrt() funciton in programming.
Required knowledge for this exercise is:
Before writing any program you just imagine about output screen first. For example: what input to be given, and output to be displayed. Let's have a look at the below example:
INPUT:
Enter any number to find square root: 625
OUTPUT:
Square root of 625.00 is = 25.00
Logic to find square root of a given number:
Step by step logic to find square root of a given number.
1) Print a massage to the user like "Enter any number to find square root:" using printf();
2) Input a number using scanf(); and store it in a variable num.
3) Now calculate square root using built-in function sqrt();
4) At last print the result of square root. that's it!
Program to calculate square root of a given number using sqrt() function:
Output:
Note: We use header file #include <math.h> since, it contains the declaration of sqrt() function. Visit to more about function and what is header file.
In above example, statements scanf("%lf", &num); format specifier %lf is used for double data type.
And statements, printf("Square root of %.2lf is = %.2lf", num, sroot); %.2lf is used to print the number in decimal format upto 2 digits after dot. For Example: 625.00, 25.00 etc.
Visit to know more about Format specifier.
![](https://1.bp.blogspot.com/-lJ032BJI94Q/X4ipUPtN2GI/AAAAAAAACSs/cS6fBwan9yQBdk_fc6XRAhmocOOa2IPLQCLcBGAsYHQ/s320/Programming.png)
![](https://1.bp.blogspot.com/-zQn-y7fhFik/YLi8qbneaGI/AAAAAAAACrI/V_GVh5i94fssrE37V_AJiqgz21T8s9CAgCPcBGAYYCw/s320/Banner1.png)
![](https://1.bp.blogspot.com/-gmKYAtzLob0/X5KV37IV1sI/AAAAAAAACT8/v7-nc7S2pAUCDQpZvJgcBo17fOiZ37Q6wCLcBGAsYHQ/s320/Job%2BInterview%2BSkills.png)
![](https://1.bp.blogspot.com/-uOwbXCHRWi0/X5KV4Ox89UI/AAAAAAAACUA/XJTxI1jFv5s7HODVnBKXs5AVzaRg_FemgCLcBGAsYHQ/s320/WebDesigning.png)
![](https://1.bp.blogspot.com/-zQn-y7fhFik/YLi8qbneaGI/AAAAAAAACrI/V_GVh5i94fssrE37V_AJiqgz21T8s9CAgCPcBGAYYCw/s320/Banner1.png)
![](https://1.bp.blogspot.com/-gmKYAtzLob0/X5KV37IV1sI/AAAAAAAACT8/v7-nc7S2pAUCDQpZvJgcBo17fOiZ37Q6wCLcBGAsYHQ/s320/Job%2BInterview%2BSkills.png)
![](https://1.bp.blogspot.com/-1wlFAhlf1Tg/X4ipTqmsrWI/AAAAAAAACSk/hbA5yzIWIpQHFVM5Q8DzG9_U8-I0BsPJQCLcBGAsYHQ/s320/HW.png)
![](https://1.bp.blogspot.com/-gmKYAtzLob0/X5KV37IV1sI/AAAAAAAACT8/v7-nc7S2pAUCDQpZvJgcBo17fOiZ37Q6wCLcBGAsYHQ/s320/Job%2BInterview%2BSkills.png)
![](https://1.bp.blogspot.com/-HjTj0VEhg38/X5KV2TSF9nI/AAAAAAAACTk/dl0t2hQ3cP8nH8Vp2xnzClh3dGpyrBrbgCLcBGAsYHQ/s320/Blogging.png)
![](https://1.bp.blogspot.com/-PpK2776r0h4/X5KV34uGW9I/AAAAAAAACT4/EveLCjuu8R848djxa4Nkmantqa9O5pL8ACLcBGAsYHQ/s320/Interview%2BQ%2526A.png)
![](https://1.bp.blogspot.com/-zQn-y7fhFik/YLi8qbneaGI/AAAAAAAACrI/V_GVh5i94fssrE37V_AJiqgz21T8s9CAgCPcBGAYYCw/s320/Banner1.png)
Help others by sharing this page.
![](https://lh3.googleusercontent.com/-YHJx9KRn5n0/WFt46p7yV2I/AAAAAAAABJ4/VInfJae6dYEr6hPWsy62CWfKXXhVMi1HACEwYBhgLKtQDAL1OcqzCtoeJ-i2dap0xXlyTzO7oa4gl7ISXXXUU3JFpJ-1I9ZoLTzaXCWKFnc8lqUtjI4GDkkfuHpmhrLbzmW8MCTjsV9eU7pCZzjuNDsRH2O0toLnmE-WwxjhMHW4ANmE36hxVPCjEe5yUsts1kkh3D-ieuhWfuTY4y_qy8B931M08I6w8B2QLoa-ecdFIopHhBZUXJzV7uT_gFXLCOUa2VxYrbzjLVFRyJXgnBDkPakqLtbSMLabAOhBGDssBAyPoXT0ba1UvwTroN0-UXcTY-UjnlC73V957_IX6HtWUnTIW4--Y_ztDWOAYgGWoDjHWgmVkFOB98diRcRVXjieHHGALfnQKUQuIddHsAA2dP1bkVXI94B2EHegYQRut3zDK3246xhbWrOn7ZoFri2zF_uMUAV3XFkeAIMnADvOF4yKwyx_ehH0xPkj1x3fensBVm7JH1uEI-Eg9zv_dJN_pZHdCNO9tobyDYruKvY8pTHxtpLyZSDzJHLoVs6ovr7_dspUkASUw5DMIlIHFJoVymq0mszqBrypz3d55fQjjZV6WKSq5xJeKPR6uNfw-r3kERqE53oXnhum5rGY_fSoqyMAwdSJkktSt4Pz5z0EDcf6IMNDH7PsF/w139-h140-p/WP_20161029_16_18_44_Selfie.jpg)
Ahmad Irshad
Author & Editor
I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP
Sunday, June 14, 2020
C
Subscribe to:
Post Comments (Atom)
0 Comments:
Post a Comment
Please don't enter any spam link in the comment box.