two integer numbers as inputs

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Number of digits

int main()

{
int c=0;
int i=3856;

int l=i; while(l>0)

{
l=l/10;

c++;

} printf("%d",c);

return 0; }

Summation of digits

int main()

{
int sum=0; int i=384;

int l=i; while(l>0) {

sum+=l%10; l=l/10;
}

printf("%d",sum);

return 0; }

 

 

Alice likes to create new definitions for various mathematical facts. She has, therefore,
recently defined equality of two numbers as below:
Two integer numbers are equal if they have the same number of digits, and the
summation of their digits are equal.
For instance, 21 is not equal to 201, because although the sums of their digits are equal
(either of them sums to 3), they have different lengths. However, 21 is equal to 30,
because they have the same length and sum to the same number, 3. As two more
examples, 741 is equal to 525, but 953 is not equal to 9152.
Write a C program that repeatedly receives two integer numbers as inputs, compares
them and prints out their equality based on Alice's definition of equality. At the end of
the loop, the user can decide to try again or to exit.
For simplicity, you can assume that the user only enters positive numbers.
Sample execution:
Please enter the first integer number: 3285
Please enter the second integer number: 3591
Numbers are equal.
Do you want to try again? (1/yes, 0/no)1
Please enter the first integer number: 305
Please enter the second integer number: 4121
Numbers have different length.
Do you want to try again? (1/yes, 0/no)1
Please enter the first integer number: 210
Please enter the second integer number: 220
Numbers are not equal.
Do you want to try again? (1/yes, 0/no) 1
Please enter the first integer number: 400
Please enter the second integer number: 301
Numbers are equal.
Do you want to try again? (1/yes, 0/no) 0
Goodbye!
Transcribed Image Text:Alice likes to create new definitions for various mathematical facts. She has, therefore, recently defined equality of two numbers as below: Two integer numbers are equal if they have the same number of digits, and the summation of their digits are equal. For instance, 21 is not equal to 201, because although the sums of their digits are equal (either of them sums to 3), they have different lengths. However, 21 is equal to 30, because they have the same length and sum to the same number, 3. As two more examples, 741 is equal to 525, but 953 is not equal to 9152. Write a C program that repeatedly receives two integer numbers as inputs, compares them and prints out their equality based on Alice's definition of equality. At the end of the loop, the user can decide to try again or to exit. For simplicity, you can assume that the user only enters positive numbers. Sample execution: Please enter the first integer number: 3285 Please enter the second integer number: 3591 Numbers are equal. Do you want to try again? (1/yes, 0/no)1 Please enter the first integer number: 305 Please enter the second integer number: 4121 Numbers have different length. Do you want to try again? (1/yes, 0/no)1 Please enter the first integer number: 210 Please enter the second integer number: 220 Numbers are not equal. Do you want to try again? (1/yes, 0/no) 1 Please enter the first integer number: 400 Please enter the second integer number: 301 Numbers are equal. Do you want to try again? (1/yes, 0/no) 0 Goodbye!
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Fundamentals of Input and Output Performance
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education