Advertisement
fiveriverflow

code

Mar 29th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int biggestDigit(int x);
  5. bool isPrime(int x);
  6.  
  7. int main() {
  8.   int x = 0;
  9.   while (x < 1000) {
  10.     cout << "Please enter an integer greater than 1000: ";
  11.     cin >> x;
  12.   }
  13.   cout << "The largest digit in " << x << " is: " << biggestDigit(x) << endl;
  14.   cout << "List of Prime Numbers from 1 to 100:";
  15.   for (int i = 1; i <= 100; i++) {
  16.     if (isPrime(i))
  17.         cout << " "  << i;
  18.   }
  19.   cout << endl;
  20.   return 0;
  21. }
  22.  
  23. int biggestDigit(int x) {
  24.   int max = 0;
  25.   int current;
  26.   while (x != 0) {
  27.     current = x % 10;
  28.     if (current > max) {
  29.       max = current;
  30.     }
  31.     x /= 10;
  32.   }
  33.   return max;
  34. }
  35.  
  36. bool isPrime(int x) {
  37.   if (x < 2) {
  38.       return false;
  39.   }
  40.   for (int i = 2; i < (x / 2 + 1); i++) {
  41.     if (x % i == 0) {
  42.       return false;
  43.      }
  44.   }
  45.   return true;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement