I want to print a float number with it's digits extending to 20000 digits after the decimal i.e. if the number is 10/3, it should print 3.333333333333333333333333333...20000 or more times.
So, how do I print something like that?
Also, do tell the solution for C and C++ as well...
The code I used was:

#include<iostream>
#include<math.h>
#include<conio.h>
using namespace std;
int main(){
    printf("%f",(sqrt(2)));
    getch();
    return 0;
    }

It gave me output: 1.414214

I cannot use a imported library in this program.
So, is their no other way of getting a solution as I want.
I want to calculate sqrt(2) to the maximum level of digits possible...

In your last reply, you gave a link to a question. I got a solution for it.

#include<iostream>
#include<conio.h>
using namespace std;
int main(){
    char a[15];
    gets(a);
    char b='1';
    for (int i=0;a[i]!='\0';i++){
        cout<<a[i];
        if ((a[i]!='1')&&(a[i]!='0')){
                                  b='2';
                                  break;
                                  }
        }
    b=='1'?(cout<<"It is binary...\n"):(cout<<"It is not binary...\n");
    getch();
    return 0;
    }

Even though I solved it but I am not quite happy with the solution as it takes a limited input. If I take a larger array, then I would be wasting memory space.
Rest all is correct I guess..?? :confused:

And to my question... It is also a question at spoj.pl
I will try to make that program too, pretty soon...

float stores with 6 digits of precision. I recommend you go for double (15 digits)
& try to output it like

double var=sqrt(static_cast<double>(2));
printf("%Lf2.15", var);

Edited 6 Years Ago by nbaztec: n/a

This article has been dead for over six months. Start a new discussion instead.