0

ok this is my code so far i have to use " isprime" to calculate prime number how do i do thatand where do i put it.thank you

#include<stdio.h>
main()
{
static int n=0, number=1; // static: so value is not lost
int fibi (int n, int number);
printf ("Following are the first 25 Numbers of the Fibonacci Series:\n");
printf ("1 "); //to avoid complexity
fib (n,number);
}
fib (int n, int number)
{
static int i=1; //i is not 0, cuz 1 is already counted in main. 
int fibo;
if (i==40)
{
printf ("\ndone"); //stop after 25 numbers
}
else 
{
fibo=n+number;
n=number; //important steps
number=fibo; 
printf ("\n%d", fibo);
i++; // increment counter 
fib (n,number); //recursion
}
}
4
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by wollacott
0

Don't make it so darn complicated. Here's a basic Fibonacci function that will never end:

void fib (int num1, int num2)
{
   num1 += num2;
   fib (num2, num1);
}

The rest is up to you.

0

You check for Prime right after this line: printf ("\n%d", fibo); Did you start with the Isprime function? If so: show some code.

Another question: is recursion a requirement for your assignment?

Niek

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.