Calculating Square root without using sqrt() function

#include<stdio.h>
int main(int argc, char *argv[])
{
    float j=0.0001,i;
    float num=atoi(argv[1]);
    if(argc!=2)
        exit(1);
    for(i=0;i<num;i=i+j)
    {
        if((i*i)>num)
            break;
    }
    i=i-j;
    printf("%.3f",i);
    return 0;


}

Post a Comment

2 Comments

  1. Please check this code:

    #include
    int main(int argc, char*argv[])
    {
    Printf("\n enter a no.");
    n=atoi(argv[1]) ;
    for(i=0.01; i*i<n; i=i+0.01)
    {
    Printf("\n %0.02f",i);
    }
    }

    ReplyDelete
    Replies
    1. Your code will get some errors. You can also compile it to know.
      you haven't specified datatype of i

      Delete