Question about Computers & Internet

1 Answer

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

Posted by on

1 Answer

  • 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
  • 202 Answers

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

1 Suggested Answer

6ya6ya
  • 2 Answers

SOURCE: I have freestanding Series 8 dishwasher. Lately during the filling cycle water hammer is occurring. How can this be resolved

Hi,
a 6ya expert 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 repairmen in the US.
the service is completely free and covers almost anything you can think of (from cars to computers, handyman, and even drones).
click here to download the app (for users in the US for now) and get all the help you need.
goodluck!

Posted on Jan 02, 2017

Add Your Answer

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

2 Answers

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

1 Answer

I need my puk number for a galaxy core prime


Hi Tammy, If you've locked your cell phone through entering an incorrect pin number 3 times then you need a Puk code, Ring your service provider and they will give you the FREE Puk code.....
If you lock your cell phone again sometime in the future and you're still with the same service provider you can use that same Puk code.. CHEERS..

May 11, 2016 | Samsung Galaxy Cell Phones

1 Answer

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

1 Answer

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

1 Answer

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

1 Answer

How do i unlock a lg prime so i can use it threw another cell phone provider


It is possible for your phone to be unlocked permanently from other networks worldwide. just use the codes that will be supplied to you by an LG UNLOCK CODE provider. You may have to enter your phone brand and model, IMEI numbers which can be retrieved by pressing *#06# on your phone keypad and the network and country the phone was purchased from. Once all requirements are met, the LG PRIME unlock code will be sent to you right away.

Dec 13, 2010 | LG Cell Phones

1 Answer

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

1 Answer

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

1 Answer

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

Not finding what you are looking for?
Computers & Internet Logo

Related Topics:

211 people viewed this question

Ask a Question

Usually answered in minutes!

Top Computers & Internet Experts

Brian Sullivan
Brian Sullivan

Level 3 Expert

27725 Answers

kakima

Level 3 Expert

100387 Answers

David Payne
David Payne

Level 3 Expert

14160 Answers

Are you a Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...