Sunday, 22 October 2017

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;


}

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

Featured Post

TCS Latest Test Patern ( For On-Campus Drives )

Tata Consultancy Services is software services consulting company whose  headquarter is situated in Mumbai, India. It is the Asia’s larges...