Jump to content
wildchild

need help with a C code

Recommended Posts

Posted

#include <stdio.h>
#include <stdlib.h>

int bf = 1;
int cf = 2;
int cn = 2;

void fibo(int n){
int i, t;
for (i = cn + 1; i <= n; i++){
t = cf;
cf += bf;
bf = t;
}
cn = n;
}

int isprime(int n){
int i;
for (i = 2; i <= n / 2; i++){
if (n % i == 0) return 0;
}
return 1;
}

int main(void)
{
int i = 0, j = 0, n;
printf("Cate numere prime din sirul lui Fibonacci doriti sa fie afisate=");
scanf("%d", &n);
if (n >= 0){
printf("%d\n", bf);
j++;
}
while (j < n){
i++;
fibo(i);
if (isprime(cf)){
printf("%d\n", cf);
j++;
}
}
getch();
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...