0% found this document useful (0 votes)
15 views7 pages

While Loop Programs

The document describes three programming problems involving Strong Numbers, Twisted Palindrome Numbers, and vehicle production calculations. Each problem specifies input and output formats, constraints, and examples, while emphasizing the use of while loops and arithmetic operations without utilizing string conversions or built-in functions. The goal is to implement solutions that adhere to these constraints and correctly identify Strong Numbers, determine palindromes, and calculate the number of two-wheelers and four-wheelers based on given data.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views7 pages

While Loop Programs

The document describes three programming problems involving Strong Numbers, Twisted Palindrome Numbers, and vehicle production calculations. Each problem specifies input and output formats, constraints, and examples, while emphasizing the use of while loops and arithmetic operations without utilizing string conversions or built-in functions. The goal is to implement solutions that adhere to these constraints and correctly identify Strong Numbers, determine palindromes, and calculate the number of two-wheelers and four-wheelers based on given data.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Use only while loop and conditional statements only:

Strong Number
A Strong Number is a number whose value is equal to the sum of the
factorials of its digits.

Definition

For a given positive integer N, compute the factorial of each digit in N


and find their sum.

• If the sum is equal to N, then N is a Strong Number.


• Otherwise, it is not a Strong Number.

Example

145

1! + 4! + 5!
= 1 + 24 + 120
= 145

→ 145 is a Strong Number

123

1! + 2! + 3!
=1+2+6
=9

→ 123 is not a Strong Number

Input Format

A single integer N

Output Format
Print "Strong Number" if N is a Strong Number
Otherwise, print "Not a Strong Number"

Instruction

• must use nested while loops to solve the problem.


• The outer while loop should extract each digit of the number.
• The inner while loop should calculate the factorial of that digit.
• Not suppose to use factorial method from math module
• Don’t create function using def keyword

Sample Input

145

Sample Output

Strong Number
Next Strong Number
A Strong Number is a number whose value is equal to the sum of the
factorials of its digits.
Example:
145 = 1! + 4! + 5! = 1 + 24 + 120 = 145
Task
Given an integer N, find the smallest Strong Number greater than N.
Conditions:Must follow these rules while solving the problem:
Use only while loops for iteration.
Nested while loops must be used to compute factorials of digits.
Do not use for loops.
Do not use string conversion (e.g., str()).
Do not use slicing (e.g., [::-1]).
Do not use built-in functions like [Link]().
The solution must use only arithmetic operations to extract digits (%, //).

Input
150

Output
40585

Explanation
The next Strong Number after 150 is 40585.
Twisted Palindrome Number
A number is called a palindrome if it reads the same forwards and
backwards.
Given an integer N, perform the following steps:
Reverse the number N to obtain R.
Add N + R.
Check whether the resulting number is a palindrome.
Print:"Palindrome" if the resulting number is a palindrome.
"Not Palindrome" otherwise.
Input
An integer N
Output
Print "Palindrome" or "Not Palindrome"
Constraints
• 0 ≤ N ≤ 10⁹
• Do not use string conversion (e.g., str()).
• Do not use slicing (e.g., [::-1]).
• Do not use any string methods.
• The solution must be implemented using only arithmetic
operations and while loops to reverse numbers.

Example 1
Input
121
Process
Reverse(121) = 121
121 + 121 = 242

Output
Palindrome
Example 2
Input
123
Process
Reverse(123) = 321
123 + 321 = 444
Output
Palindrome
AUTOMOBILE COMPANY

An automobile company manufactures both a two wheeler (TW) and four


wheeler (FW). A company manager wants to make the production of both
types of vehicle according to the given data below:
1st data, total number of vehicle (Two wheelers + four wheelers)
2nd data, Total number of wheels=w
The task is to find how many two-wheelers as well as four-wheelers need
to manufacture as per the given data.
Total Number of Two wheelers and Four Wheelers must be positive, else
return 1
Ex: Input:
200 ----value of V
540 ----value of W
Output:
TW=130 FW=70
Explanation:
130+70=200 Vehicles
(70*4)+(130*2)=540 wheels
Constraints:
2<=W
W%2=0
V<W
Print “INVALID INPUT”, if inputs did not meet the constraints
Sample Input:
200
580
Sample Output:
110
90
Sample Input:
10
19
Output:
INVALID INPUT

You might also like