Computer Science, asked by dhupper, 11 months ago

Write a program to find the Nth term in this series. The value N in a positive integer that should be read from STDIN. The Nth term that is calculated by the program should be written to STDOUT. Other than the value of Nth term , no other characters / string or message should be written to STDOUT. For example, when N=14, the 14th term in the series is 17. So only the value 17 should be printed to STDOUT.

Answers

Answered by qwtiger
2

Answer:

In C Language:

#include<stdio.h>

#define MAX 1000

void fibonacci(int n)

{

int i, t1 = 0, t2 = 1, nextTerm;

for (i = 1; i<=n; i++)

{

nextTerm = t1 + t2;

t1 = t2;

t2 = nextTerm;

}

printf("%d", t1);

}

void prime(int n)

{

int i, j, flag, count =0;

for (i=2; i<=MAX; i++)

{

flag = 0;

for (j=2; j<i; j++)

{

if(i%j == 0)

{

flag = 1;

break;

}

}

if (flag == 0)

if(++count == n)

{

printf("%d", i);

break;

}

}

}

int main()

{

int n;

scanf("%d", &n);

if(n%2 == 1)

fibonacci (n/2 + 1);

else

prime(n/2);

return 0;

}

Similar questions