English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

outputs annser in rational form and computes the close rational approximatation to e which is 2.17 where e==1+1/1!+1/2!+1/3!+1/4!+...... answer should be in form of a/b

2006-10-19 21:46:58 · 4 answers · asked by Jessie N 1 in Computers & Internet Programming & Design

rational form and computes e where is the sum of 1+1/1!+1/2!+1/3!+1/4!+1/5! ... and result is aproximated using 2.17 using struc Rational {int a, int b} to represent a/b
new structure typedef struct Rational Rational; and declare Rationa to sruct Rational. using operations of addition and multiplication. how do i implement these in the program Rational R_init(int a, int b); Rational R_add (rational x, Rational Y); Rational R_mult(Rational x, Rational Y); int R_show (Rational x ); R_init should return a rational representation for a/b, R_add should add two rational arguments it is passed and R_show should print our the rational number (a/b)

2006-10-19 22:44:12 · update #1

4 answers

float e = 1;
int counter = 1;
int denominator;

// 1+ 1/1 + 1/(1*2) + 1/(1*2*3)

while (e<=2.7)
{

denominator = 1;

for(int i=1;i<=counter;i++)
{
denominator=denominator * i;
}
e=e+1/(denominator);
counter++;

}


does this work for you?

2006-10-19 22:02:34 · answer #1 · answered by c00kies 5 · 0 0

I certainly won't write it, but here is what I would do. Make a structure to represent a rational number. You want to make each member as big as you can to handle large numbers:

struct rational {
long int numerator;
long int denominator;
};

Then you need to write a routine that adds 2 of them; I would set it up like

boolean add(struct rational *first, struct rational *second, struct rational *result) {}

The return value is 0 for an error (ie denominator of 0), otherwise the result is returned in RESULT. This subroutine will need to find the LCD of the denominators and make the result in RESULT.

You will also need a similar routine to multipley, but that is easy, just multiply top and bottom.

Finally, you will need some way to enter and print. Printing should be something like

void printRational(struct rational *num) {

}

2006-10-20 05:00:01 · answer #2 · answered by sofarsogood 5 · 0 0

Yeah could be interesting, be sure to let me know what it turns out like.

2006-10-20 04:54:18 · answer #3 · answered by John S 4 · 0 0

Wow, I can't believe anyone was idiot enough to do your homework for you!

Rawlyn.

2006-10-20 05:16:27 · answer #4 · answered by Anonymous · 0 1

fedest.com, questions and answers