C Tutorial

# C Program to find Square Root of a Number

## How to find square root in C program ?

```#include<math.h>

double sqrt(double)
```

## C Program To Find Square Root of a Integer

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

void main ()
{
int number;
double sqrt_val=0;
printf("\nEnter number: ");
scanf("%d", &number);

sqrt_val = sqrt((double)number);

printf("Square root of %d: %lf\n", number, sqrt_val);
}
```
Output:
```\$ cc square-root.c -o a.out -lm
\$ ./a.out

Enter number: 4
Square root of 4: 2.000000
\$ ./a.out

Enter number: 16
Square root of 16: 4.000000
\$ ./a.out

Enter number: 36
Square root of 36: 6.000000

```

## Finds Square Root of a Float Number

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

void main ()
{
float number;
double sqrt_val=0;
printf("\nEnter number: ");
scanf("%f", &number);

sqrt_val = sqrt((double)number);

printf("Square root of %f: %lf\n", number, sqrt_val);
}
```
Output:
```\$ cc square-root.c -o a.out -lm
\$ ./a.out

Enter number: 4.4
Square root of 4.400000: 2.097618
\$ ./a.out

Enter number: 26
Square root of 26.000000: 5.099020

```

## Finds Square Root of a Double Number

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

void main ()
{
double number;
double sqrt_val=0;
printf("\nEnter number: ");
scanf("%lf", &number);

sqrt_val = sqrt(number);

printf("Square root of %lf: %lf\n", number, sqrt_val);
}
~
```
Output:
```\$ cc square-root.c -o a.out -lm
\$ ./a.out

Enter number: 34565.78
Square root of 34565.780000: 185.918746
\$ ./a.out

Enter number: 89242948294.23232
Square root of 89242948294.232315: 298735.582571
```

C Tutorial