Write a program that calculate the Square Root of a given number
Input:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <stdio.h> #include <math.h> void main (void) { double x = 0.0, square_root = 0.0; printf("Enter a number: "); scanf("%lf", &x); if (x >= 0) { square_root = sqrt(x); printf("Square Root of %3.3lf = %3.2lf", x, square_root); } else printf(“Square root cannot be calculated”); } |
Result:
Case1:
Enter a Number: 16 Square Root = 4.00
Case2:
Enter a Number: -56
Square root cannot be calculated
No comments:
Post a Comment