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
#include
main()
{
long int a,b,c;
printf("Enter the number: ");
scanf("%ld",&a);
for (b=2;b { c= a%b; if (c==0) goto cool; } printf("\nThe number is goddamned prime!"); goto fool; cool: printf("\nThis ain't a Prime number you dumbo!"); fool: printf("\n"); } By the way I am not sure what your query really was. I gave the above program to check whether a number is prime or not. If you mean to generate prime numbers between 2 (which is of course the first prime number) and a given number g and also want to know the number of prime numbers between the two, well here is it: #include #include main() { long int a=2,i=2,c,count=0,g; printf("Prime numbers upto what number should be generated? "); scanf("%ld",&g); printf("\nFollowing is the list of prime numbers:\n"); while (a<=g) {
#include<stdio.h>
#include<conio.h>
main()
{
int i,j,n;
printf(" Enter the number upto which you want to find prime number ");
scanf("%d",&n);
printf("\n");
for(i=2;i<=n;i++)
{
for(j=2;j<=i-1;j++)
if(i%j==0)
break;
if(i==j) printf("\n\t%d",i);
}
getch();
}
//for example if u want to find prime number between 1 to 100 enter 100..
// u will get prime number between 1 to 100
//tested in bloodshed dev c++
Oh, dude, you wanna find prime numbers? Alright, here's a simple C program for ya: You loop through numbers from 1 to 500, check if each number is prime by dividing it only by numbers up to its square root (efficient, right?), and if it's only divisible by 1 and itself, boom, you got a prime number. Print those bad boys out and voilà, you're done. Like, easy peasy, lemon squeezy!
Write a program to find the number and sum of all integers from 100 to 300 that are divisible by 11
It should not be even (except for 2), and must not be dividable with any odd number between 3 and its square-root.
flow t prime numberchar
write a c++ program to convert binary number to decimal number by using while statement
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.
see the program
To get all tutorials of "c programming" Reference:cprogramming-bd.com/c_page2.aspx# prime number
Since there is an infinite set of prime numbers the answer would be infinity.
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; }
find the program in c-pgms.blogspot.com
Write a program to find the number and sum of all integers from 100 to 300 that are divisible by 11
#include<stdio.h> #include<conio.h> void main() { int n,i; clrscr(); printf("Enter a Number:"); scanf("%d",&n); printf("\n\nPrime Factors of %d is: ",n); for(i=2;i<=n;i++) { if(n%i==0) { printf("%d,",i); n=n/i; i--; if(n==1) break; } } getche(); } this program will find the prime factors of a given numbe any assistance mail at :- devilllcreature@yahoo.com thank you
#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