This blog is under construction

Monday 8 July 2013

C program to calculate square root and square of a number

Write a C program to calculate square root and square of a number.


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

  int main() {
        float num, root, square;

        /* get the input value from the user */
        printf("Enter your input:");
        scanf("%f", &num);

        /* find the square root for the given input */
        root = sqrt(num);

        /* find the square of the given number  */
        square = num * num;

        /* print the square root value */
        printf("Square root of %.0f is %.2f\n", num, root);

        /* print the square value */
        printf("Square of %.0f is %.0f\n", num, square);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter your input:101
  Square root of 101 is 10.05
  Square of 101 is 10201






See Also:

No comments:

Post a Comment