To print the prime number in a given range
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
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Let's create a program to display prime no in a given range:
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