answersLogoWhite

0

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)

{

for (i=2;i

{

c=(a%i);

if (c==0)

goto cool;

else

continue;

}

printf("\n%ld",a);

++count;

cool: ++a;

}

printf("\nTotal number of prime numbers between 2 and %ld is %ld. ",g,count);

}

For both these programs, simply copy-paste them into your compiler and have your result. Hope you got what you wanted...

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

How do you find prime no in gwbasic program?

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


Write a c program to find given number is prime or not?

Yes, do write, or if you're too lazy to your homework, use google.


What is the code of a c program that will read in a positive integer value and determine If the integer is a prime number and If the integer is a Fibonacci number?

see the program


How do you write a c program to get a range from user and give a list of prime numbers?

To get all tutorials of "c programming" Reference:cprogramming-bd.com/c_page2.aspx# prime number


Write a C program to find the sum of all prime numbers?

Since there is an infinite set of prime numbers the answer would be infinity.


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.


Write a c program to find out the prime numbers between 1 to 500?

Here is a simple program to generate prime numbers upto a given specific number /*Prime No. from 1 to 50*/ /*By-Himanshu Rathee*/ #include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int i,j,n; clrscr(); printf(" Enter the number upto which we have to find the prime number: "); scanf("%d",&amp;n); printf("\n"); for(i=2;i&lt;=n;i++) { for(j=2;j&lt;=i-1;j++) if(i%j==0) break; /*Number is divisble by some other number. So break out*/ if(i==j) printf("\t%d",i); /*Number was divisible by itself (that is, i was same as j)*/ } /*Continue loop upto nth number*/ getch(); }


What is the Program for composite and prime numbers in c?

#include&lt;iostream.h&gt; #include&lt;conio.h&gt; int main() { int i,n; clrscr(); cout&lt;&lt;"PROGRAM TO CHECK IF THE NUMBER IS PRIME OR NOT:"&lt;&lt;endl; cout&lt;&lt;"Enter a number:"; cin&gt;&gt;n; for(int i=2;i&lt;n;i++) { if(n%i==0) cout&lt;&lt;"\nTHE NUMBER IS COMPOSITE"&lt;&lt;endl; else cout&lt;&lt;"\nTHE NUMBER IS PRIME"&lt;&lt;endl; } return 0; }


Program for sin series in c language?

find the program in c-pgms.blogspot.com


Program in c language to find prime factors of a given number?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int n,i; clrscr(); printf("Enter a Number:"); scanf("%d",&amp;n); printf("\n\nPrime Factors of %d is: ",n); for(i=2;i&lt;=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


Writes a c program to find the sum of all integers between 1 and n?

Write a program to find the number and sum of all integers from 100 to 300 that are divisible by 11


How can you check whether a number is prime or not by a C program using functions?

#include&lt;iostream.h&gt; #include&lt;conio.h&gt; void prime(int n) { clrscr(); int num; cout&lt;&lt;"enter the numbers"&lt;&lt;endl; cin&gt;&gt;num; prime(num); getch(); } void prime(int n) { int prime=1,i; for(i=2;i&lt;=n/2;i++) if(n%i==1) prime=0; if(prime==1) cout&lt;&lt;"the number"&lt;&lt;n&gt;&gt;"is prime"; else cout&lt;&lt;"the number"&lt;&lt;n&lt;&lt;"is not prime"; }

Trending Questions
An electric clothes dryer has a resistance of 8 ohms It draws 30 A of current What is the voltage in volts of the wall outlet that it is plugged into? What 3 things make a robot a robot? If no power is being delivered to a specific circuit when the breaker is on is the breaker bad? What are the elements of hydraulic systems? How many doped regions in a Bipolar transistor? Who invented the rope bridges? Can you convert an ac fridge to dc? What is the environmental considerations of gas pipe line? What are the factors that influence the first step of the decomposition technique identifying deliverable for a project? In chickens rose comb R is dominant over single comb r When a heterozygous hybrid Rr rose-combed rooster is mated with a single-combed rr hen what combination of phenotypes will be shown in? What is the advantage of silicon diode in other types in changing AC to DC? What is called robots in SEO? How does being an excellent writer contribute to being an excellent computer programmer? What is the meaning of platation system? How do you open a jar file on a mac? Which of the following are helpful pointers for a successful briefing ssd1? How do you fix a chewed wire? What four checks operator should carry out before picking up load load? What happens if there are to many computer programmers in one human habitat and they are all trying to make a living on programming computers? Why the capacitor voltages are unbalance in flying capacitor multilevel inverter?