BM Balmiki Mandal 24 Feb 2023 5 views 0 comments C Programming

Exploring the sqrt() Function in C programming language

Understanding the sqrt() Function in C Programming

The sqrt() function is a built-in mathematical function in the C programming language that is used to calculate the square root of a given number. It is defined in math.h header file.

The syntax of the sqrt() function is as follows

double sqrt(double x);

where x is the argument whose square root is to be calculated. The return type of the sqrt() function is double, which is the square root of the argument x.

Here is an example code snippet that demonstrates how to use the sqrt() function in C:

#include<stdio.h>
#include<math.h> 

int main() {
    double num, result;
    
    printf("Enter a number: ");
    scanf("%lf", &num);
    
    result = sqrt(num);
    
    printf("Square root of %.2lf = %.2lf", num, result);
    
    return 0;
}

In this example, the user is prompted to enter a number. The scanf() function is used to read the number from the user, and the sqrt() function is used to calculate the square root of the number. The result is then displayed using the printf() function.

0 Comments

No comments yet, Be the first to comment.

Post a Comment

Please sign in to post a comment.

Related Posts

Bit wise operators Assignment

Bitwise Operators practical assignment: Take runtime input, bit-level manipulation, and different data units r...

AG Anvesh G 27 Sep 2026
Understanding Float and Double Binary Representation in C

Understanding Float and Double Binary Representation in CIntroduction:When we store decimal numbers such as 10...

AG Anvesh G 31 May 2026
Topic-wise C Programming Interview Questions

C Programming Interview Questions – Topic Wise1. IntroductionC programming is one of the most important langu...

AG Anvesh G 30 May 2026