Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have to code this in C++ I don't know how to do this the way my professor wanted it Dont use the int type

image text in transcribed
I have to code this in C++
I don't know how to do this the way my professor wanted it
"Dont use the int type in this assignment or you could get incorrect answers and/or warnings!
Use the datatype long, a long is a type that can hold a really big integer! I will not use
numbers larger than 15 for the input!
YOU ARE NOT ALLOWED TO CONVERT THE NUMBER INTO A STRING VARIABLE,
OR READ A STRING VARIABLE, THAT WOULD BE WAY TOO EASY
"
Assigament 6: Factorial Digit Sum 6789012 Description In this program, you will compute the factorial of a number and then sum up each of its digits. Once again, if the number entered is negative or cannot be interpreted as a number, re-prompt the user and you will keep re-prompting the user until a valid positive integer has been entered. The definition of factorials for say n is n 1) (n -2). (n -3) 1. so for example the factorial of 5 which is expressed as 5! is 5. 4.3.2.1 which is 120. So the sum of the digits of 5! would be 3 because 5! is 120 and then l 2 0 is 3. Computing the factorial is the "easy part, now you will have to break the number apart into integers and sum them up, and no, you cannot convert the integer into a string variable because that would be way too easy To break a number into individual digits, you will need do a series to of integer divisions and mod divisions to grab each digit and then remove that digit from the number. Here's a hint, if we have the number 12345, we want to get 1 out of this number (the leftmost digit), what will we divide 12345 by to get the number 1? After we get the 1, now we want to remove that 1 from 12345 to get 2345 (what will we need to do now Once we have 2345, we want to get the leftmost digit again (which is 2), so we perform the same operation as earlier and then we add that 2 to the 1, and once again we need to get rid of the 2 to get 345 and we do this a number of times. The number of times we will do this is int Clog10Cn)) 1, taking the base 10 logarithm of a number (casted to an integer) and added by 1 tells you how many digits the number has, if you don't believe me, try it! Don't use the int type in this assignment or you could get incorrect answers and/or warnings! Use the datatype long, a long is a type that can hold a really big integer! I will not use numbers larger than 15 for the input! YOU ARE NOT ALLOWED TO CONVERT THE NUMBER INTO A STRING VARIABLE OR READ A STRING VARIABLE, THAT WOULD BE WAY TOO EASY

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions