NOTE: in mathematics, the square root of a negative number is not real; in C therefore, passing such a value to the square root function is an error. Given a double variable named areaOfSquare write the necessary code to read in a value, the area of some square, into areaOfSquare and print out the length of the side of that square. HOWEVER: if any value read in is not valid input, just print the message "INVALID".

Respuesta :

Answer:

# include<math.h>

# include<stdlib.h>

# include<stdio.h>

int main()

{

    int choice;

    double area;

    printf("Enter the area of Square:");

    scanf("%lf", &area);

    printf("Enter the choice: 1, 2:");

    scanf("%d", &choice);

    switch(choice)

    {

        case 1:if(area<0.00)

                        {

                        printf(" INVALID");

                        break;

                        }

                      else

                        {

                        printf("side of square: %lf", sqrt(area));

                        break;

                       }

                       break;

        case 2: break;

    }

return 0;

}

Explanation:

Here, if area is less than 0 then invalid message is printed out. And if area is more than 0 then the sqrt is calculated and the side of a square length is being printed out. And that is what is required. lf is for double. And math.h is included to make use of the sqrt function.

ACCESS MORE