Write a program in C language to print all prime numbers between 1 and a given number n input by user at run time.
This C program will display all prime numbers from 1 to a user supplied number n.// cprime, prime in c++, prime series in c++, n prime
// C++ program to input a number n
//then prints prime number series from 1 to n
//that is prints all prime between 1 to n
cprime-numbers-series-from-1-to-N-program-source-code |
#include <iostream>
using namespace std;
int checkPrimeNumber(int);
int main() {
bool isPrime;
int n, num;
cout<<"Enter the value of n:";
cin>>num;
for(int n = 2; n <= num; n++)
{
// if n is prime then boolean variable isPrime will be true
isPrime = checkPrimeNumber(n);
if(isPrime == true)
cout<<n<<" ";
}
return 0;
}
int checkPrimeNumber(int n) {
bool isPrime = true;
for(int i = 2; i <= n/2; i++) {
if (n%i == 0)
{
isPrime = false;
break;
}
}
return isPrime;
}
//Output:
//Enter the value of n:50
//2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
https://easycodebook.com/2023/08/listbox-add-remove-move-items-visual-programming/
ReplyDeleteListbox Windows Forms Application To Add items, Remove Selected item, View selected item, move select item form list box 1 to list box 2, and move all items to list box 2
ReplyDelete