A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a program in C to generate mersenne primes within a range of numbers
Q:

Write a program in C to generate mersenne primes within a range of numbers

0

Write a program in C to generate mersenne primes within a range of numbers


Expected Output:
Input a upper limit [range from 1 to upper limit]: 1000
Mersenne prime numbers are:
3 7 31 127

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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


void GenAllPrim(int n1, bool prarr1[])
{
    for (int i=0; i<=n1; i++)
        prarr1[i] = true;
 
    for (int p=2; p*p<=n1; p++)
    {
        if (prarr1[p] == true)
        {
            for (int i=p*2; i<=n1; i += p)
                prarr1[i] = false;
        }
    }
}
void chkMerPrime(int nm)
{
    bool prarr1[nm+1];
    GenAllPrim(nm,prarr1);
    for (int j=2; ((1<<j)-1) <= nm; j++)
    {
        long long num = (1<<j) - 1;
        if (prarr1[num])
            printf(" %lli ",num);
    }
}
int main()
{
    int n ;
	printf("\n\n Generate Mersenne primes within a range of numbers:\n");
	printf("--------------------------------------------------------\n");
	printf(" Input a upper limit [range from 1 to upper limit]: ");
    scanf("%d",&n);	
    printf(" Mersenne prime numbers are: \n");
    chkMerPrime(n);
    printf("\n\n");
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now