Search:

Submit Article

# Program to compute and print out the decimal notation for the reciprocal of each input integer

Posted By: Easy Tutor     Category: C++ Programming     Views: 13003

## Code for Program to compute and print out the decimal notation for the reciprocal of each input integer in C++ Programming

``` # include <iostream.h>
# include <fstream.h>
# include <string.h>
# include <stdlib.h>
# include <conio.h>
# include <math.h>

int main( )
{
clrscr( );

fstream File("CP-08.txt",ios::in|ios::nocreate);

if(!File)
{
cout<<"\n Unable to open the input file."<<endl;
cout<<"\n Press any key to exit.";

getch( );
exit(EXIT_FAILURE);
}

char Quotient[5]={NULL};
char Input_integer[85]={NULL};
char Reciprocal[200]={NULL};

char *Endptr=NULL;

int quotient=0;

longdouble divisor=0;
longdouble divident=0;
longdouble remainder=0;

do
{
strset(Input_integer,NULL);
strset(Reciprocal,NULL);

File.getline(Input_integer,80);

if(strcmp(Input_integer,"0")==0)
break;

divisor=0;
divident=1;
quotient=0;
remainder=0;
Endptr=NULL;

divisor=_strtold(Input_integer,&Endptr);

if(divisor>1)
{
divident=10;

strcpy(Reciprocal,"0.");
}

while(divisor>divident)
{
divident*=10;

strcat(Reciprocal,"0");
}

do
{
remainder=fmod(divident,divisor);
quotient=divident/divisor;
divident=remainder;

strset(Quotient,NULL);
itoa(quotient,Quotient,10);
strcat(Reciprocal,Quotient);

if(divisor>divident)
divident*=10;

if(divisor>divident)
{
divident*=10;

strcat(Reciprocal,"0");
}

if(divident<divisor)
break;
}
while(1);

if(Reciprocal[strlen(Reciprocal)-1]=='0')
Reciprocal[strlen(Reciprocal)-1]=NULL;

cout<<Reciprocal<<endl;
}
while(1);

getch( );
return 0;
}

```
Share:

 Easy Tutor author of Program to compute and print out the decimal notation for the reciprocal of each input integer is from United States. Easy Tutor says Hello Friends,I am Free Lance Tutor, who helped student in completing their homework. I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] comI have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada. I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.Thanks,Happy Programming :) View All Articles