Solved

Posted on 2000-03-14

main()

{

int a = 0, b = 1, c = 0 /* initialize the series to 0, 1 */

int sum(); /* declare function to calc sums */

printf("fibonacci\n");

printf("%5d \n", a);

printf("%5d \n", b);

do

{

c = sum(a, b);

printf("%5d\n", c);

a = b;

b = c;

}

while (c < 10000);

}

int sum (x, y) /* the parameters x and y receive the values of */

int x, y; /* the two arguments passed by sum(a, b) in main() */

{

return x + y;

}

Question: I need to use a subtract function to calculate and display the differences between the suceeding numbers in the fibonacci series.

I need to calculate and display thr quotients of the succeding fibonacci series in a third data column, right next to the differences. For the divisions I need a division function named divide to perform this calculation. To preserve the decimal accuracy of thequotients I will need to declare and use a float type function with two arguments

{

int a = 0, b = 1, c = 0 /* initialize the series to 0, 1 */

int sum(); /* declare function to calc sums */

printf("fibonacci\n");

printf("%5d \n", a);

printf("%5d \n", b);

do

{

c = sum(a, b);

printf("%5d\n", c);

a = b;

b = c;

}

while (c < 10000);

}

int sum (x, y) /* the parameters x and y receive the values of */

int x, y; /* the two arguments passed by sum(a, b) in main() */

{

return x + y;

}

Question: I need to use a subtract function to calculate and display the differences between the suceeding numbers in the fibonacci series.

I need to calculate and display thr quotients of the succeding fibonacci series in a third data column, right next to the differences. For the divisions I need a division function named divide to perform this calculation. To preserve the decimal accuracy of thequotients I will need to declare and use a float type function with two arguments

2 Comments

mvjohn: for accuracy, use a double, not a float type. float types are not much use (except to save memeory when you are using a LOT of them).

Also, you are using yucky old-style C declarations. This is bad programming practice. You should declare your sum function as:

int sum (int x, int y);

and define it as:

int sum (int x, int y) {

return x+y;

}

I think, without giving too much away, your subtract and divide functions would be

int subtract (int x, int y) {

return x-y;

}

double divide (double x, double y) {

return x/y;

}

then you'd change

printf("%5d\n", c);

into

printf("%5d %5d %8.5f\n", c, subtract(c,b), divide(c,b));

PS: you'll probaby want to put some error checking in the divide routine to avoid division by zero.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Title | # Comments | Views | Activity |
---|---|---|---|

Making a Sample Win32 DLL project Using Visual Studio 2010 Professional | 4 | 92 | |

FMX StringGrid1->Canvas->FillR |
3 | 128 | |

How to gracefully close the c++ 11 thread? | 3 | 83 | |

FMX TCameraComponent Problem | 2 | 53 |

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**17** Experts available now in Live!