• Language

    C

  • Description

    It determines the square root if the entered value is a positive number. If the value is a negative value it says that it is an imaginary solution.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main (void)
{
    float a_number, square_root;
    printf ("Enter the value of a number: ");
    scanf ("%f", &a_number);
    (void) getchar ();
    if(a_number>=0)
    {
        square_root=sqrt(a_number);
        printf ("Real root\n");
    }
    else
    {
        square_root=sqrt(-a_number);
        printf ("Imaginary root\n");
    }
    printf ("Value of square root: %g\n", square_root);
    putchar ('\n');
    system ("pause");
    return EXIT_SUCCESS;
}