#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();
}
#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();
}
this is not the correct program is is not giving correct output..
ReplyDeletethis is the correct program...this is giving correct output...
ReplyDeletethis program works fine!!... thanks...
ReplyDeletek,l
ReplyDeletegood logic...I never thought of this idea..
ReplyDeleteThis is Goog
ReplyDeleteIdea But Its shown Complicated But in Really Its Simple I think You Are Smart
can u explain me the logic?
ReplyDelete#include
ReplyDelete#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;
}
}
#include
ReplyDelete#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);
}
easy method is
ReplyDelete#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
can use clrscr();
ReplyDeleteand getch();
its is working tested.
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...
DeleteC++ program to find Square Root of a Number
ReplyDeleteThanks for sharing this code. It's really helpful. Keep sharing.