I Am Facing A Problem Working With Prime Number.
Could You Send The Code?
From,
Chetna
I cannot send you the code. Your problem is not defined clearly.
"Working with Prime number" means what ? Are you manipulating prime
numbers ?
If you want to display prime numbers, then this is the algorithm
1. put a for loop from 4 to the highest number you want
[ for example 1 to 100 print prime numbers, like wise]
Here 2,3 are prime numbers print them directly if they are in the range.
0 and 1 are neither prime nor composite so leave them.
2. Have a flag with initial value true
3. Nest with another for loop, Let the variable of outer for loop be i and
inner be j
4. Now intialise j from zero to square root of i
5. In this inner loop check whether j divides i, that is reminder is zero
make use of "%" operator.
6. If the reminder is zero, then make the flag false and break the inner loop
7. After inner loop, before closing outer loop; check the flag, if it is true
then display variable i, since it is prime and close the outer for loop
Is it all clear now ???
Post whether this is the one you are looking for
Hi this is the code for vb.net To find the given no is prime or not.The same syntax and formulae using in C.So try it .
Dim n, i As Integer
Dim x As Boolean //Delclaration
n = TextBox1.Text //Using Scanf function to get the no
For i = 2 To n - 1 //for(i=2;i<n;i++ )
If (n Mod i = 0) Then // if (n %i =0)
x = True
End If
Next //Close for brace
If x = True Then
MsgBox("Not a Prime") //Printf function.
Else
MsgBox("Prime")
End If
what is the easiest code that would give the following output....
Please enter two integers: 9 13
9: 3
10: 2 5
11: Prime
12: 2 3 4 6
13: Prime
There are 2 prime numbers.
The average value of the prime numbers is 12.00
Please enter two integers.
email :eutykeli@comca st.net
[code=c]
printf("Please enter two integers: 9 13\n");
printf(" 9: 3\n 10: 2 5\n");
printf(" 11: Prime\n 12: 2 3 4 6\n");
printf(" 13: Prime\n There are 2 prime numbers.\n");
printf(" The average value of the prime numbers is 12.00\n");
printf(" Please enter two integers.\n");
[/code]
You're welcome.
kind regards,
Jos
ps. maybe one big puts() would've been better? simpler?
[code=c]
printf("Please enter two integers: 9 13\n");
printf(" 9: 3\n 10: 2 5\n");
printf(" 11: Prime\n 12: 2 3 4 6\n");
printf(" 13: Prime\n There are 2 prime numbers.\n");
printf(" The average value of the prime numbers is 12.00\n");
printf(" Please enter two integers.\n");
[/code]
You're welcome.
kind regards,
Jos
ps. maybe one big puts() would've been better? simpler?
Comment