Search Results

Search found 3 results on 1 pages for 'user278330'.

Page 1/1 | 1 

  • C++ question on prime numbers.

    - by user278330
    Hello. I am trying to make a program that determines if the number is prime or composite. I have gotten thus far. Could you give me any ideas so that it will work? All primes will , however, because composites have values that are both r0 and r==0, they will always be classified as prime. How can I fix this? int main() { int pNumber, limit, x, r; limit = 0; x = 2; cout << "Please enter any positive integer: " ; cin >> pNumber; if (pNumber < 0) { cout << "Invalid. Negative Number. " << endl; return 0; } else if (pNumber == 0) { cout << "Invalid. Zero has an infinite number of divisors, and therefore neither composite nor prime." << endl; return 0; } else if (pNumber == 1) { cout << "Valid. However, one is neither prime nor composite" << endl; return 0; } else { while (limit < pNumber) { r = pNumber % x; x++; limit++; } if (r == 0) cout << "Your number is composite" << endl; else cout << "Your number is prime" << endl; } return 0; }

    Read the article

  • C++ question on prime numbers.

    - by user278330
    Hello. I am trying to make a program that determines if the number is prime or composite. I have gotten thus far. Could you give me any ideas so that it will work? All primes will , however, because composites have values that are both r0 and r==0, they will always be classified as prime. How can I fix this? int main() { int pNumber, limit, x, r; limit = 0; x = 2; cout << "Please enter any positive integer: " ; cin >> pNumber; if (pNumber < 0) { cout << "Invalid. Negative Number. " << endl; return 0; } else if (pNumber == 0) { cout << "Invalid. Zero has an infinite number of divisors, and therefore neither composite nor prime." << endl; return 0; } else if (pNumber == 1) { cout << "Valid. However, one is neither prime nor composite" << endl; return 0; } else { while (limit < pNumber) { r = pNumber % x; x++; limit++; } if (r == 0) cout << "Your number is composite" << endl; else cout << "Your number is prime" << endl; } return 0; }

    Read the article

  • C++ Perfect Number. Need some help revising.

    - by user278330
    I need some help revising this. It keeps only displaying 0s as the temp. Thank you. // A program to determine whether the input number is a perfect number // A perfect number is defined by the sum of all its positive divisors excluding itself // 28: 1+2+3+7+14 = 28. int perfect, limit, divisor; cout << "Please enter a positive integer in order to define whether it is a perfect integer or not: " ; cin >> perfect; cout << endl; int temp = 0; int prevtemp = 0; limit = 1; divisor = 1; while (limit < perfect) { if ((perfect % divisor) == 0) divisor = prevtemp; limit++; divisor++; temp = prevtemp + temp; cout << temp << endl; } if (perfect == temp) cout << "Your number is a perfect number!" << endl; else cout << "Your number is not a perfect number" << endl; return 0;

    Read the article

1