1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include <iostream>
/*
Create a C++ program that
1] accepts two integers from the user
2] determines the parity of the first integer (even or odd)
3] the sign of the first integer
4] if the first integer is an element of 2, 3, 5, 7, 11, 13, 17, 19, 23,29 (first ten primes)
5] if the two integers are consecutive.
*/
int main()
{
//****
// 1
//****
int firstNum, secondNum;
std::cout << "Enter the first number: ";
std::cin >> firstNum;
std::cout << "Enter the second number: ";
std::cin >> secondNum;
//****
// 2
//****
if (firstNum % 2 == 0)
{
std::cout << "The first number is even.\n";
}
else
{
std::cout << "The first number is odd.\n";
}
//****
// 3
//****
// the sign of the first integer
// if it is less than zero it is negative...
// structurally, this will look a lot like the check
// already done for parity (even or odd) above
//****
// 4
//****
// if the first integer is one of the first 10 primes
// create some container, an array perhaps, that holds the first 10 primes
// use a loop to check the first integer against each item in the container
// if you find a match, then the first num is one of the first 10 primes
//****
// 5
//****
// What does it mean to be consecutive? That means the two integers differ
// by exactly one. Subtract them. If the answer is 1 or -1, then they're
// consecutive.
return 0;
}
|