Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
877 B
0
Indexable
Never
#include <stdio.h>

// Function to check if a number is prime
int isPrime(int n) {
    if (n <= 1) {
        return 0; // Not prime
    }
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return 0; // Not prime
        }
    }
    return 1; // Prime
}

// Function to find nth Fibonacci term
int fibonacci(int n) {
    int a = 0, b = 1, c, i;
    if (n == 0)
        return a;
    for (i = 2; i <= n; i++) {
        c = a + b;
        a = b;
        b = c;
    }
    return b;
}

int main() {
    int n;
    
    printf("Enter the value of n: ");
    scanf("%d", &n);
    
    int fib = fibonacci(n);
    
    if (isPrime(fib)) {
        printf("The %dth Fibonacci term %d is prime.\n", n, fib);
    } else {
        printf("The %dth Fibonacci term %d is not prime.\n", n, fib);
    }
    
    return 0;
}
Leave a Comment