3. Digits
Prompt the user, enter a number in the range [1000, 9999].
If input failure, complain and die
If outside the range, complain and die
Output the square of the number, and the sum of the squares of the digits, with explanatory text.
//////////////////////////////////////////////////
An example run might go as:
# in [1000, 9999]:
1234
square is 1522756
sum of squares of digits is 30
As you have not mentioned any language, I am answering this question in C++
PROGRAM -
#include <iostream>
using namespace std;
int main()
{
int number, sumOfSquares=0, digit;
long squaredNumber=0;
cout<<"Enter a number in [1000, 9999] : ";
cin>>number; //prompt user
if(number>9999 || number<1000) { //check if input is
correct
cout<<"Wrong input!";
exit(0); //if not die
}
squaredNumber = number * number; //compute square of the
number
while(number) { //loop to compute sum of the square of the digits
of the number
digit = number%10;
number=number/10;
sumOfSquares+=digit*digit;
}
//output result
cout<<"Square of the number is: "<<squaredNumber;
cout<<"\nSum of squares of digits of the number:
"<<sumOfSquares;
}

OUTPUT


3. Digits Prompt the user, enter a number in the range [1000, 9999]. If input failure,...
(Java Please) Sum of Digits Write a program that will sum the digits of a number input by the user. For example, if the user enters the number 1234, the sum of the digits will be 10 (1 + 2 + 3 + 4 = 10). The user will enter a number with at least 4 digits (greater than 1000). That value will be sent to a method which will return the sum. Sample Output 1: SUM OF DIGITS -------------...
C++ 1: Grade Prompt the user for name (first name only, only one word) and score (which will be input as a fixed point number). Input the values, c&d on input failure. The score should be in the range [0, 100], otherwise c&d. Compute the grade and output with explanatory text. The grade for most students according to [85, 100]: A [73, 85): B [61, 73): C [49, 61): D [0, 49): F (Note that in the above I use...
C++ Loops homework Prompt the user for a desired password, input the password. Your program may assume without checking that there is no input failure and that the password contains no white space. Let's say the rules for a legal password are: # chars must be in [4, 8] # digs must be >= 2 The password must contain at least one letter of each case The password must contain at least one char that's not a letter or digit...
Python 3: Write a program in python that asks the user to enter a number that contains 4 digits, i.e. in the range [1000-9999]. Your program MUST take it as a number integer. Print each digit on a separate line.
4-card poker Prompt the user, input 4 fixed point values, which can be input in any order. C&d on input failure. Each of the 4 numbers is supposed to be in the range [1, 13], otherwise c&d. Output the appropriate one of the following 5 messages: 4 of a kind 3 of a kind two pairs one pair nothing For example, if the input were 5 5 1 5 then your program would output 3 of a kind I don't...
1. Prompt the user for one of the arithmetic operators ('op'): +, -, *,/, or ** 2. Prompt the user for two input integers ('a' and'b') 3. The input numbers can be positive or negative 4. Perform the arithmetic operation using the two input numbers 5. The first entered number ('a') is the left side, the second ('b') the right side of the operation For exponentiation, the first number is the base, the second the exponent Print (display) the following...
With your partner, brainstorm a program that will ask the user for a number of digits to be stored. The program should then create an array of that size and then prompt the user for numbers to fill each position in the array. When all of the positions are filled, display the contents of the array to the user. Create a new Project named FillArray and a new class in the default packaged named FillArray.java. You and your partner should...
C++ please! (1) Prompt the user to enter the name of the input file. The file will contain a text on a single line. Store the text in a string. Output the string. Ex: Enter file name: input1.txt File content: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue! (2) Implement a PrintMenu() function,...
Write C++ program to prompt user to enter a 3-digits number, say 371, to a variable called num. Then store each digit of this inputted number to three different variables called digit1, digit2 and digit3. Hence, when number entered is 371, digit1 is 3, digit2 is 7 and digit3 is 1. Display the value of inputted number followed by digit1, digit2 and digit3. Hint: You have to use / and % operator in this question.
QUESTION 12 Write a program that would prompt the user to enter an integer. The program then would displays a table of squares and cubes from 1 to the value entered by the user. The program should prompt the user to continue if they wish. Name your class NumberPowers.java, add header and sample output as block comments and uploaded it to this link. Use these formulas for calculating squares and cubes are: square = x * x cube = x...