A number is a Prime number if it is divisible by only 1 and itself. So make use of for loop and check for this condition.
int i,num,flag = 0;//num is the number to check
scanf("%d", &num);
for( i=2; i if( num%i == 0)//it has other divisors flag = 1; } if( !flag) printf("The number is prime\n"); else printf("The number is not prime\n");
#include<stdio.h>
void main()
{
int n = 0, i = 3, count = 0, loop = 0;
printf("Enter the number of prime numbers required\n");
scanf("%d",&n);
if ( n >= 1 )
{
printf("First %d prime numbers are :\n",n);
printf("2\n");
}
for ( count = 2 ; count <= n ; )
{
for ( loop = 2 ; loop <= i - 1 ; loop++ )
{
if ( i%loop i )
{
printf("%d\n",i);
count++;
}
i++;
}
}
#include<iostream> #include<cmath>
bool is_odd (const unsigned num) {
return num & 1 == 1;
}
bool is_even (const unsigned num) {
return is_odd (num) == false;
}
bool is_prime (const unsigned num) {
if (num<2) return false;
if (is_even (num) == true) return num==2; // 2 is the only even prime
const unsigned max = (unsigned) sqrt (num) + 1;
unsigned div;
for (div=3; div<max; div+=2) {
if (num%div == 0) return false;
}
return true;
}
int main (void) {
std::cout << "Enter a whole number: ";
std::cin >> num;
if (is_even (abs (num)) {
std::cout << "The number is even\n";
}else{
std::cout << "The number is odd\n";
}
if (is_prime (abs (num)) {
std::cout << "The number is prime\n";
}else{
std::cout << "The number is composite\n";
}
}
flow t prime numberchar
I am providing a succinct and easy to understand version of the program. I have run it in 3-4 compilers and it works perfect. Mind you, you should not enter a number more than 2147483647 (which is the largest number a variable can process in C!). If you do, no problem, but it will display all numbers above it, including the even numbers to be prime. So here you are:#include#includemain(){long int a,b,c;printf("Enter the number: ");scanf("%ld",&a);for (b=2;b
write a c++ program to convert binary number to decimal number by using while statement
#include <iostream.h> main() { int a; cout<<"enter a number : "; cin>>a; cout<<endl; if (a%2-1) cout<<"it is a prime number"; else cout<<"it is not a prime number" return 0; } ------------------------------------------ output: enter a number : 30 it is a not a prime number
how to write a program that counts automorphic number from 1 to 999
see the program
To get all tutorials of "c programming" Reference:cprogramming-bd.com/c_page2.aspx# prime number
10 input "enter a no."; n 20 for i = 1 to n 30 if n mod i = 0 then c = c +1 40 next i 50 if c = 2 then print "prime number" else print "not a prime number" 60 end
Yes, do write, or if you're too lazy to your homework, use google.
By learning how to program on C+.
#include<iostream.h> #include<conio.h> int main() { int i,n; clrscr(); cout<<"PROGRAM TO CHECK IF THE NUMBER IS PRIME OR NOT:"<<endl; cout<<"Enter a number:"; cin>>n; for(int i=2;i<n;i++) { if(n%i==0) cout<<"\nTHE NUMBER IS COMPOSITE"<<endl; else cout<<"\nTHE NUMBER IS PRIME"<<endl; } return 0; }
Use Wolfram|Alpha... go to the related link below, Wolfram|Alpha, and type in (is __ (number) prime) and then the program will compute that and tell you if it is prime or composite.
Prime numbers are numbers that are only divisible by themselves and the number 1. You can write a program to print all prime numbers from 1 to 100 in FoxPro.
#include<iostream.h> #include<conio.h> void prime(int n) { clrscr(); int num; cout<<"enter the numbers"<<endl; cin>>num; prime(num); getch(); } void prime(int n) { int prime=1,i; for(i=2;i<=n/2;i++) if(n%i==1) prime=0; if(prime==1) cout<<"the number"<<n>>"is prime"; else cout<<"the number"<<n<<"is not prime"; }
fdsgfhgdfhgdf
c.23
Product of a prime number and a composite number results in a composite number.Now consider the product of a composite number(a) and a prime number(b) is equal to c.i.e. c = a x bIt is clear that c is divisible by both a and b.Also c is divisible by itself and 1, this means that c has more than two factors.A number having more than two factors is composite, therefore product of a prime number and a composite number results in a composite number.