Question
C++ program Given a non-negative integer num, add all the digits and determine if this sum is prime. A prime is a natural number (greater
C++ program
Given a non-negative integer num, add all the digits and determine if this sum is prime. A prime is a natural number (greater that 1) that have no factors other than one and itself. If the result is no (The sum of digits is NOT prime), output the largest prime number that is less than the input number. For example: Input a number 38, the result is Yes (Prime). Input a number 1998, The result is No (Not Prime). The largest prime number that is less than the input number is 1997. Input a number 15, The result is No (Not Prime). The largest prime number that is less than the input number is 13.
Note: 1. The data type of input variable num is int.
2. The input integer may have any number of digits.
3. You can assume that the input is a non-negative integer and is greater than 1.
4.It is NOT necessary to include any other library, except
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started