Write a program to print all prime numbers between a and b w

Write a program to print all prime numbers between a and b, where a and b are variables that are to be initialized from user inputs.

Solution

Matlab code-

a=input(\'Enter the first number\');

b=input(\'Enter the second number\');

n=a:b

for i=a:1:b

p = isprime(i);%Logical alue

------

C code-

#include <stdio.h>
int main()
{
    int a, b, i, flag;
    printf(\"Enter the first number: \");
    scanf(\"%d\", &a);
    printf(\"Enter the second number: \");
    scanf(\"%d\", &b);

    printf(\"Prime numbers between %d and %d are: \", a, b);

    while (a < b)
    {
        flag = 0;

        for(i = 2; i <= a/2; ++i)
        {
            if(a % i == 0)
            {
                flag = 1;
                break;
            }
        }

        if (flag == 0)
            printf(\"%d \", a);

        ++a;
    }

    return 0;
}

 Write a program to print all prime numbers between a and b, where a and b are variables that are to be initialized from user inputs.SolutionMatlab code- a=inpu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site