Prime numbers are positive whole numbers that are only divis

Prime numbers are positive whole numbers that are only divisible by 1 and itself. Numerology is any belief in divine, mystical relationship between a number and one or more coinciding events^1. In this assignment, you will identify all the days in the year that have one of the following attributes: A single-digit prime number that occurs on a Monday A prime number that is between 10-19 and occurs on a Friday A prime number that is >19 and occurs on a Sunday Assignment: Create a 2-level nested loop (months of year, and days of the month) to cycle through all the days of the calendar year. Test for one of the following conditions on each day, and output the month/day if true. Create an enumeration for the day of the week to aid in readability of your code. Initialize the first day of the year as Sunday. (Change this when you\'re done to see its effect). Your program must have the following: 2-level nested loops (months and days) enum of the days of the week continue statement when days of the month are 28 or less break statement for months with less than 31 days (i.e. Feb or April)

Solution

C++ code:

#include <bits/stdc++.h>
using namespace std;

bool isprime(int n)
{
   for (int i = 2; i < n ; ++i)
   {
       if(n%i == 0)
       {
           return false;
       }
   }
   return true;
}

int main()
{
   int day = 6; // 0:monday , 1:tue, .... 4:fri,5:sat, 6:sunday
   for(int m = 1; m <= 12; m++)
   {
       for (int d = 1; d <= 31; d++)
       {
           if(m == 2 and d > 29)
           {
               break;
           }
           if( (m == 4 or m == 6 or m == 8 or m == 10 or m == 12) and d >= 30)
           {
               break;
           }
           if( (d >=1) and ((d <= 9)) and (isprime(d)) and (day == 0))
           {
               cout << \"Month = \" << m << \" date = \" << d << \" day : Monday\" << endl;
           }
           if( (d >=11) and (d <= 19) and (isprime(d)) and (day == 4))
           {
               cout << \"Month = \" << m << \" date = \" << d << \" day : Friday\" << endl;
           }          
           if( (d >19) and (isprime(d)) and (day == 6))
           {
               cout << \"Month = \" << m << \" date = \" << d << \" day : Sunday\" << endl;
           }          
           day = (day + 1)%7;
       }
   }
   return 0;
}

Sample Output:

Month = 1 date = 2 day : Monday
Month = 1 date = 13 day : Friday
Month = 1 date = 29 day : Sunday
Month = 2 date = 17 day : Friday
Month = 3 date = 5 day : Monday
Month = 4 date = 2 day : Monday
Month = 4 date = 13 day : Friday
Month = 4 date = 29 day : Sunday
Month = 5 date = 1 day : Monday
Month = 5 date = 19 day : Friday
Month = 6 date = 5 day : Monday
Month = 7 date = 31 day : Sunday
Month = 8 date = 1 day : Monday
Month = 8 date = 19 day : Friday
Month = 9 date = 7 day : Monday
Month = 9 date = 11 day : Friday
Month = 11 date = 3 day : Monday
Month = 11 date = 23 day : Sunday
Month = 12 date = 7 day : Monday
Month = 12 date = 11 day : Friday

 Prime numbers are positive whole numbers that are only divisible by 1 and itself. Numerology is any belief in divine, mystical relationship between a number an
 Prime numbers are positive whole numbers that are only divisible by 1 and itself. Numerology is any belief in divine, mystical relationship between a number an

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site