1. prime ring

hi i am newbie here, i am not trying to ask for the answer here...
i am just asking for opinion

can someone let me know what should i include in this type of question please.

http://acm.uva.es/p/v5/524.html

2. I'm not sure I understand the question....? Could you explain more clearly?

But, if you're wondering how you find primes...

Code:
```#include <windows.h>
#include <iostream>
#include <math.h>
using namespace std;

BOOL IsPrime(int n);

int main() {
IsPrime(13);
}

BOOL IsPrime(int n) {
int i;
BOOL prime;

cout << "Enter number to prime-test";
cin >> n;

for(i = 2; i <= sqrt((double) n); i++)
if(n % 1 == 0)
is_prime = false;
}```
That should work if I got my logic right.

3. please visit this website for understanding http://acm.uva.es/p/v5/524.html

thank you

4. please make it simple as i am the newbie of C++..

5. > can someone let me know what should i include in this type of question please.
Blackroot has already given you an answer - a function to check whether a given number is prime or not is a good start.

I suppose other functions would be to
- check a whole ring for being prime, as discussed in the assignment
- generate all possible rings according to some input
- get and validate some input from the user.

6. Originally Posted by Blackroot
BOOL IsPrime(int n) {
int i;
BOOL prime;

cout << "Enter number to prime-test";
cin >> n;

for(i = 2; i <= sqrt((double) n); i++)
if(n % 1 == 0)
is_prime = false;
}
[/code]
This code is wrong! You should not divide by 1 -> (n%1)!!!!
here u have more efficient one
Code:
```BOOL IsPrime(int n) {

if (n<=2)
return true;

if (n%2 == 0)
return false;

for(i = 3; i <= sqrt((double) n); i+=2){
if(n % i == 0){
return false;
}
}
return true;
}```
u can check a number if it is prime by calling function with a argument that could by any number within int range!

7. i am sorry guyz.. i still dont understand ...

well can someone give example, such as i
INPUT: 4
and the OUTPUT which i done it by myself (1,2,3,4 and 1,4,3,2)
correct me if i am wrong..
can someone guide me to the process please.

8. can some one tell me how can i modify this code so that i can ask the user input from 1-16....

Code:
```int ring[16];
int m;

int main()
{
int  i, j, k;
//  insert the 1 value into first position which is ring[0]
ring[0] = 1;

while (scanf("%d", &m))
{
if (m == 0)
break;

//  printf("Get %d\n", m);
if (FindNumber(1) == true)
{
for(j=0; j<m; j++)
{
printf("%d ", ring[j]);
}
printf("\n");
}
}// end while.
system("pause");
return 0;
}```

Popular pages Recent additions