/* SQUARE ROOT VALUE WITHOUT USING LIBRARY FUNCTION */
#include<stdio.h>
#include<conio.h>
main()
{
float num,sqtval,temp;
clrscr();
printf("\n Enter a number: ");
scanf("%f",&num);
sqtval=num/2;
temp=0;
while(sqtval!=temp)
{
temp=sqtval;
sqtval=(num/sqtval+sqtval)/2;
}
printf("\n sqroot of %f number is %f ",num,sqtval);
getch();
}
OR
#include<stdio.h>
#include<conio.h>
main()
{
int i, num;
clrscr();
printf("\n Enter a number: ");
scanf("%d",&num);
for(i=1; i<=num; i++)
{
if(i*i == num)
{
printf("\n square root value = %d",i);
break;
}
}
getch();
}
No comments:
Post a Comment