Q:

How to Print Prime Number in C Programming?

0

To print the prime number in a given range

All Answers

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

Let's create a program to display prime no in a given range:

#include <stdio.h>
int main()
{
    int low, high, i, flag;
    printf("Enter two numbers: ");
    scanf("%d %d", &low, &high);
    printf("Prime numbers between %d and %d are: ", low, high);
    while (low < high)
    {
        flag = 0;
        for(i = 2; i <= low/2; ++i)
        {
            if(low % i == 0)
            {
                flag = 1;
                break;
            }
        }
        if (flag == 0)
            printf("%d ", low);
        ++low;
    }
    return 0;
}

Output:

Enter two numbers: 5 50

Prime numbers between 5 and 50 are: 5 7 11 13 17 19 23 29 31 41 43 47

Parameters used in the Program

  • #include<stdio.h> - It includes standard input output library functions. 
  • int main() - The main function is the entry point of every program in c.
  • printf() - The printf() function is used to print the data on the console.

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