# Need code how to write prime number code using c#.net

Posted by on

• Level 2:

An expert who has achieved level 2 by getting 100 points

MVP:

An expert that got 5 achievements.

Novelist:

An expert who has written 50 answers of more than 400 characters.

Governor:

An expert whose answer got voted for 20 times.

• Expert

Try the Following Five Programs

1) Program for Prime Number Generation

#include <stdio.h>
main()
{
int n,i=1,j,c;
clrscr();
printf("Enter Number Of Terms
");
printf("Prime Numbers Are Follwing
");
scanf("%d",&n);
while(i<=n)
{
c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
c++;
}
if(c==2)
printf("%d ",i)
i++;
}
getch();
}
--------------------------------------------------------------------------------------------------------------------------------------------------

2)Program for finding the prime numbers

#include <stdio.h>
#include <conio.h>
void main()
{
int n,m,k,i,max;
char c;
clrscr();
repeat: max=0;
k=2;
n=1;
printf("You want prime numbers upto:- ");
scanf("%d",&max);
printf("

");
for (i=1;i<=max;i++)
{
again: m=(n/k)*k;
if (m!=n)
k=k+1;
else
goto try1;
if (k < n/2)
goto again;
else
printf("%d",n);
printf(" ");
try1: n=n+1;
k=2;
}
fflush(stdin);
printf ("

Do you want to continue?(y/n):- ");
scanf("%c",&c);
if (c=='y')
goto repeat;
getch();

}
---------------------------------------------------------------------------------------------------------------------------------------------------

3)

1. #include <stdio.h>
2. int main(void) {
3. int n,
4. lcv,
5. flag; /* flag initially is 1 and becomes 0 if we determine that n
6. is not a prime */
7. printf("Enter value of N > ");
8. scanf("%d", &n);
9. for (lcv=2, flag=1; lcv <= (n / 2); lcv++) {
10. if ((n % lcv) == 0) {
11. if (flag)
12. printf("The non-trivial factors of %d are: \n", n);
13. flag = 0;
14. printf("\t%d\n", lcv);
15. }
16. }
17. if (flag)
18. printf("%d is prime\n", n);
19. }
---------------------------------------------------------------------------------------------------------------------------------------------------

4)

#include<stdio.h>

#include<conio.h>

void main()

{

int n,i,c=0;

clrscr();

printf("enter the number:");

scanf("%d",&n);

for(i=1;i<=n;i++)

{

if(n%i==0)

{

c=c+1;

}

}

if(c==2)

printf("number is prime");

else

printf("number is not prime");

getch();

}
-------------------------------------------------------------------------

5)
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter the number:");
scanf("%d",&a);
for(b=2;b<a/2;b++)
{
if(n%i==0)
{
printf("\n Its not a Prime number");
c=1;
break;
}
if(flag==0)
printf("\n Its a Prime Number");
getch();
}
}

Posted on Sep 12, 2008

Hi,
a 6ya Technician can help you resolve that issue over the phone in a minute or two.
Best thing about this new service is that you are never placed on hold and get to talk to real repair professionals here in the US.
Goodluck!

Posted on Jan 02, 2017

×

my-video-file.mp4

×

## Related Questions:

### Is 8 a prime number? And what are the factors for 20? And is 20 a prime number?

No it isn't as 1,2,4,8 can be used to divide it prime's are only dividable by 1 or itself only
20 is 1,2,4,5,10

Jan 23, 2017 | The Computers & Internet

### Why is it important that 1 is not a prime number

It used to be. The idea is that a prime decomposition must be unique. If you write 13=1*13, you can also write 13=1*1*1*....*1*13. If you allow 1 to be a prime number, there is no unicity of any prime factor decomposition. Any prime number would have a infinity number of prime decompositions.

Sep 28, 2014 | Computers & Internet

### I cant understand prime numbers

A prime number is a positive whole number (natural number) which cannot be divided into smaller whole numbers. In short, it can only be divided (integer division) by itself and 1.
First prime number is 2, then 3, 5, 7, 11, 13, 17, 19,
To generate a list of prime numbers the Greek Eratoshenes used a method called now the sieve Eratosthenes.

1. Write all the natural numbers up to some chosen limit (100, 259, any limit )
2. Remove 1 by crossing it ( 1 is no longer considered prime).
3. The first prime number is 2. Circle the number 2.
4. Go through the whole list crossing out all the numbers that are multiple of 2, that is 4, 6, 8,10,12, ...
5. Repeat.
6. The next prime number is 3 since it was not crossed out as a multiple of 2. Circle 3.
7. Go through the whole list crossing all the numbers that are multiples of 3, and which have not already been crossed out as multiples of 2 .
8. Number 4 has been crossed out already.
9. Next prime number is 5. Circle 5
10. Go through the whole list crossing all the numbers that are multiple of 5 and which have not been crossed out already as multiples of 2, or 3
11. Repeat:
12. Next prime number is 7. Circle 7
13. Go through the whole list again, crossing out the multiples of 7, and so on.
If you want to test the primality of a positive integer (odd number) starting by dividing it by 3 (use divisibility rules or otherwise), then divide by 5, by seven, and all subsequent prime numbers. If it is not divisible by any prime number, keep going but do not exceed the prime number that is closest yet smaller than square root of your number.

Enjoy.

Nov 26, 2013 | Office Equipment & Supplies

### What is prime factorization?

"Prime Factorization" is finding which prime numbers multiply together to make the original number.

Example : What are the prime factors of 12 ? It is best to start working from the smallest prime number, which is 2, so let's check:

12 ÷ 2 = 6
Yes, it divided evenly by 2. We have taken the first step!
But 6 is not a prime number, so we need to go further. Let's try 2 again:

6 ÷ 2 = 3
Yes, that worked also. And 3 is a prime number, so we have the answer:

12 = 2 × 2 × 3

As you can see, every factor is a prime number, so the answer must be right.

Note: 12 = 2 × 2 × 3 can also be written using exponents as 12 = 22 × 3

Jun 22, 2011 | Computers & Internet

### Generate prime nos upto n

Just do a search for Sieve of Eratosthenes to find an efficient algorithm for finding prime numbers. You can probably find source code in multiple languages for this purpose as well.

Jul 06, 2009 | Microsoft Computers & Internet

### C# code wite a program to accept a number from the user and display all the prime numbers fro zero up to the numbers entered by user?

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,rem,prime,primchk=1,chk;
clrscr();
printf("\nEnter the limit\n");
scanf("%d",&n);
printf("\n\n\nThe prime numbers are\n");
printf("\n2\t3\t");
for(primchk=1;primchk<=n;primchk++)
{
for(i=2;i<primchk;i++)
{
if(primchk%i==0)
{
chk=1;
chk=0;
break;
}
if(i==primchk-1)
{
if(chk==0)
{
printf("%d\t",primchk);
chk=0;
}
}
}
}
getch();
}

May 20, 2009 | Computers & Internet

### Code for prime numbers in c

Prime numbers can be calculated by using recursive algorithm
int i,j=1;
i++;
for (j=2;j<i;j++)
{
If (i%j==0)printf(" %d number is prime",&i );
else printf(" %d number is not prime",&i);
i++;
delay(20);
}
Ctrl break to terminate execution or other

Jan 29, 2009 | Computers & Internet

## Open Questions:

#### Related Topics:

212 people viewed this question

Level 3 Expert

Level 3 Expert