SD234 - Unit 4 - Assn B

download SD234 - Unit 4 - Assn B

of 2

Transcript of SD234 - Unit 4 - Assn B

  • Unit 4 Assignment B

    1. Programming Exercise #6 Write a program that reads a set of integers, and then finds and prints the sum of the even and odd integers. (15 points)

    =START CODE= #include using namespace std;

    int main() { //Set variables. int evenNums = 0; int oddNums = 0; int ckCount = 0; int count = 0; int val = 0;

    //Prompt for set length. cout > count;

    DoAgain: //Prompt for value in set. cout

  • 2. Programming Exercise #7 Write a program that prompts the user to input a positive integer. It should then output a message indicating whether the number is a prime number. (15 points)

    =START CODE= #include using namespace std;

    int main() { int num = 0; int count = 0;

    cout > num;

    //Check the number to see if it's prime. Break out if it's not a prime number. for(int i=2;i