PROGRAM TO FIND SQUARE ROOT OF A NUMBER

#include "stdio.h"
#include "conio.h"
main()
{
float a,b,e=0.00001,p,k;
clrscr();
textcolor(GREEN);
do {
printf(" ************************************************
);
printf(" PROGRAM TO FIND SQUARE ROOT OF A);
printf(" ************************************************
);
cprintf("ENTER A NUMBER(-1 to Quit) :");
scanf("%f",&k);

a=k;p=a*a;
while(p-k>=e)
{
b=(a+(k/a))/2;
a=b;
p=a*a;
}
printf("SQUARE ROOT IS = %f,a);
getch();
clrscr();
}
while(k!=-1);
getch();
}

13 comments:

  1. this is not the correct program is is not giving correct output..

    ReplyDelete
  2. this is the correct program...this is giving correct output...

    ReplyDelete
  3. this program works fine!!... thanks...

    ReplyDelete
  4. good logic...I never thought of this idea..

    ReplyDelete
  5. This is Goog
    Idea But Its shown Complicated But in Really Its Simple I think You Are Smart

    ReplyDelete
  6. can u explain me the logic?

    ReplyDelete
  7. #include
    #include
    float SquareRoot(float num);
    void main()
    {
    float input, ans;
    clrscr();
    printf("\n Enter The Number : ");
    scanf("%f", &input);
    ans = SquareRoot(input);
    printf("\n Square Root : %f", ans);
    getch();
    }

    float SquareRoot(float num)
    {
    if(num >= 0)
    {
    float x = num;
    int i;
    for(i = 0; i < 20; i ++)
    {
    x = (((x * x) + num) / (2 * x));
    }
    return x;
    }
    }

    ReplyDelete
  8. #include
    #include
    #include

    main()
    {
    float number, ans;

    printf("\n\n Enter Number - ", number);
    scanf("%f", &number);

    ans = sqrt(number);

    printf(" \n Squareroot of given number is %f\n\n\n", ans);
    }

    ReplyDelete
  9. easy method is
    #include
    #include
    #include
    void main()
    {
    long int a,b;
    cout<<"a=";
    cin>>a;
    b=sqrt(a);
    cout<<"the square root of << a <<"is="<<b;
    }
    easy method

    ReplyDelete
  10. can use clrscr();
    and getch();
    its is working tested.

    ReplyDelete
    Replies
    1. Hello, actually clrscr() is use to clear the screen (if it contains any previous text or output) & getch() is to just pause the screen, but if you uning DEV C/C++ then you dont need to use this, its useful in case of Turbo C...

      Delete
  11. C++ program to find Square Root of a Number

    Thanks for sharing this code. It's really helpful. Keep sharing.

    ReplyDelete