prime ring

This is a discussion on prime ring within the C++ Programming forums, part of the General Programming Boards category; hi i am newbie here, i am not trying to ask for the answer here... i am just asking for ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    71

    Exclamation 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. #2
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    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.
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    71
    please visit this website for understanding http://acm.uva.es/p/v5/524.html

    thank you

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    71
    please make it simple as i am the newbie of C++..

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,854
    > 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. #6
    Registered User
    Join Date
    Jan 2006
    Posts
    14
    Quote 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. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    71
    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. #8
    Registered User
    Join Date
    Nov 2005
    Posts
    71
    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 subscribe to a feed

Similar Threads

  1. Calculating prime factor of a huge number.
    By Bakster in forum C Programming
    Replies: 15
    Last Post: 02-20-2009, 12:06 PM
  2. prime number program with function
    By mackieinva in forum C Programming
    Replies: 17
    Last Post: 09-20-2007, 09:36 AM
  3. prime numbers, counters, help!
    By vege^ in forum C++ Programming
    Replies: 1
    Last Post: 03-10-2003, 04:32 PM
  4. Prime Wonder
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-08-2002, 12:49 AM
  5. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 05:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21