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();
}

Related Links :

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


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!