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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include <stdio.h>
#include <math.h>
/*This Program Finds The Square Roots Of Three User-Generated Variables*/
int main()
{
double x;
double y;
double z;
printf("Please Enter 3 Numbers To Take The Square Root Of:\n");
scanf("%f", &x); //This Gathers The Values for the Variables x, y, and z.
scanf("%f", &y);
scanf("%f", &z);
if(x < 0) // This Checks if x is negative, then sets it to the absolute value before taking the square root
{
while(x < 0)
{
printf("The Square Root of x is Not Possible, Considering it is Negative\n");
printf("I Will Convert it to the Positive Equivalent");
x = abs(x);
x = sqrt(x);
printf("The Square Root Of x is %f\n" , x);
}
}
if(y < 0) // This Checks if y is negative, then sets it to the absolute value before taking the square root
{
while(y < 0)
{
printf("The Square Root of y is Not Possible, Considering it is Negative\n");
printf("I Will Convert it to the Positive Equivalent");
y = abs(y);
y = sqrt(y);
printf("The Square Root Of y is %f\n" , y);
}
}
if(z < 0) // This Checks if z is negative, then sets it to the absolute value before taking the square root
{
while(z < 0)
{
printf("The Square Root of z is Not Possible, Considering it is Negative\n");
printf("I Will Convert it to the Positive Equivalent");
z = abs(z);
z = sqrt(z);
printf("The Square Root of z is %f\n" , z);
}
}
if(x == 0) // This checks if x is zero, then takes it's square root
{
printf("x = Zero, It's Square Root is Zero.\n");
}
if(y == 0) // This checks if y is zero, then takes it's square root
{
printf("y = Zero, It's Square Root is Zero.\n");
}
if(z == 0) // This checks if z is zero, then takes it's square root
{
printf("z = Zero, It's Square Root is Zero.\n");
}
if(x > 0) // This takes the x variable, if it is not negative or zero, and automatically finds the square roots
{
x = sqrt(x);
printf("%f\n", x);
}
if(y > 0) // This takes the y variable, if it is not negative or zero, and automatically finds the square roots
{
y = sqrt(y);
printf("%f\n", y);
}
if(z > 0) // This takes the z variable, if it is not negative or zero, and automatically finds the square roots
{
z = sqrt(z);
printf("%f\n", z);
}
}
|