Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! ๐ ๐นLearn advanced coding techniques in C& C++ ๐นMaster Linux internals & shell scripting ๐นDeep dive into Data Structures & Algorithms ๐นExplore Embedded Systems & Microcontrollers (8051,UART, RTOS) ๐นGet hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
Print Prime Numbers Between Two Numbers in C
✅ Print Prime Numbers Between Two Numbers in C
#include <stdio.h>
int main() {
int m, n, i, j, isPrime;
// Input range from user
printf("Enter the starting number (m): ");
scanf("%d", &m);
printf("Enter the ending number (n): ");
scanf("%d", &n);
printf("Prime numbers between %d and %d are:\n", m, n);
for(i = m; i <= n; i++) {
if (i < 2) continue;
isPrime = 1; // Assume prime
for(j = 2; j <= i / 2; j++) {
if(i % j == 0) {
isPrime = 0;
break;
}
}
if(isPrime) {
printf("%d ", i);
}
}
printf("\n");
return 0;
}
๐ Explanation:
✅ The program reads two integers m and n.
✅ It loops from m to n and checks each number for primality.
✅ For each number, it checks if it’s divisible by any number from 2 to i/2.
✅ If no divisors are found, it's a prime and printed.
๐งพ Sample Output:
Enter the starting number (m): 10 Enter the ending number (n): 25 Prime numbers between 10 and 25 are: 11 13 17 19 23
๐ Keywords:
C prime number program, prime between two numbers, C beginner practice, loop logic, prime check algorithm in C
๐ Hashtags:
#CProgramming #PrimeNumbers #LoopingInC #BeginnerC #ProgrammingBasics #InterviewPrep
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment