Programming in C
Programming in C
4th Edition
ISBN: 9780321776419
Author: Stephen G. Kochan
Publisher: Addison-Wesley
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 5, Problem 6E

Write a program that takes an integer keyed in from the terminal and extracts and displays each digit of the integer in English. So, if the user types in 932, the program should display

n

Remember to display “zero” if the user types in just a 0. (Note: This exercise is a hard one!)

Expert Solution & Answer
Check Mark
Program Plan Intro

Program Plan:

  • Include the required files
  • Define the main function
    • Declare the variable “num1”, “num2”, “rt_digit”, “val”.
    • Get the number from the user.
    • Check whether “num1” not equal to “0”.
      • Find the remainder using mod operator.
      • Divide the “number” by “10”.
      • Multiply “val” to “num” and add with the “rt_digit”.
      • Condition for while loop to check whether the “val” not equals to “10”.
        • Multiply the “val” with “10”.
      • Assign the “rt_digit” to “0”.
      • Do until the condition fails.
        • Find the remainder using mod operator.
        • Check whether the “rt_digit” equals to “1”.
          • Print the value “one”.
        • Check whether the “rt_digit” equals to “2”.
          • Print the value “two”.
        • Check whether the “rt_digit” equals to “3”.
          • Print the value “three”.
        • Check whether the “rt_digit” equals to “4”.
          • Print the value “four”.
        • Check whether the “rt_digit” equals to “5”.
          • Print the value “five”.
        • Check whether the “rt_digit” equals to “6”.
          • Print the value “six”.
        • Check whether the “rt_digit” equals to “7”.
          • Print the value “seven”.
        • Check whether the “rt_digit” equals to “8”.
          • Print the value “eight”.
        • Check whether the “rt_digit” equals to “9”.
          • Print the value “nine”.
        • While loop to check the condition whether the “num2” not equal to “0”.
Program Description Answer

Program to display the numbers to their equivalent words.

Explanation of Solution

Program:

//Include required header files

#include <stdio.h>

//Main function

int main()

{

//Declare the required variable

int num1 = 0, rt_digit = 0, num2 = 0, val = 1;

//Get the number from the user

printf("\nEnter a number: ");

scanf("%i", &num1);

//While loop to check the condition

while (num1 != 0)

{

//Find the remainder using mod operator

rt_digit = num1 % 10;

//Divide the "num1" by "10"

num1 = num1 / 10;

//Multiply "val" to "num" and add with the "rt_digit"

num2 = num2 * val + rt_digit;

//While loop to check the condition

while (val != 10)

{

//Multiply "val" with "10"

val = val * 10;

}

}

//Assign the "rt_digit" to "0"

rt_digit = 0;

//Do until the condition fails

do {

//Find the remainder using mod operator

rt_digit = num2 % 10;

//Check whether the "rt_digit" equals to "0"

if (rt_digit == 0)

{

//Print the value zero

printf("zero ");

}

//Check whether the "rt_digit" equals to "1"

else if (rt_digit == 1)

{

//Print the value one

printf("one ");

}

//Check whether the "rt_digit" equals to "2"

else if (rt_digit == 2)

{

//Print the value two

printf("two ");

}

//Check whether the "rt_digit" equals to "3"

else if (rt_digit == 3)

{

//Print the value three

printf("three ");

}

//Check whether the "rt_digit" equals to "4"

else if (rt_digit == 4)

{

//Print the value four

printf("four ");

}

//Check whether the "rt_digit" equals to "5"

else if (rt_digit == 5)

{

//Print the value five

printf("five ");

}

//Check whether the "rt_digit" equals to "6"

else if (rt_digit == 6)

{

//Print the value six

printf("six ");

}

//Check whether the "rt_digit" equals to "7"

else if (rt_digit == 7)

{

//Print the value seven

printf("seven ");

}

//Check whether the "rt_digit" equals to "8"

else if (rt_digit == 8)

{

//Print the value eight

printf("eight ");

}

//Check whether the "rt_digit" equals to "9"

else

//Print the value nine

printf("nine ");

//Divide the "num2" by "10"

num2 = num2 / 10;

//While loop to check the condition

} while (num2 != 0);

//Return the value 0

return 0;

}

Sample Output

Enter a number:  56

five six 

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
I would like to get help to resolve the following case
Last Chance Securities The IT director opened the department staff meeting today by saying, "I've got some good news and some bad news. The good news is that management approved the payroll system project this morning. The new system will reduce clerical time and errors, improve morale in the payroll department, and avoid possible fines and penalties for noncompliance. The bad news is that the system must be installed by January 1st in order to meet new federal reporting rules, all expenses from now on must be approved in advance, the system should have a modular design if possible, and the vice president of finance would like to announce the new system in a year-end report if it is ready by mid-December." Tasks 1. Why is it important to define the project scope? How would you define the scope of the payroll project in this case? 2. Review each constraint and identify its characteristics: present versus future, internal versus exter- nal, and mandatory versus desirable. 3. What…
2. Signed Integers Unsigned binary numbers work for natural numbers, but many calculations use negative numbers as well. To deal with this, a number of different methods have been used to represent signed numbers, but we will focus on two's complement, as it is the standard solution for representing signed integers. 2.1 Two's complement • Most significant bit has a negative value, all others are positive. So, the value of an n-digit -2 two's complement number can be written as: Σ2 2¹ di 2n-1 dn • Otherwise exactly the same as unsigned integers. i=0 - • A neat trick for flipping the sign of a two's complement number: flip all the bits (0 becomes 1, or 1 becomes 0) and then add 1 to the least significant bit. • Addition is exactly the same as with an unsigned number. 2.2 Exercises For questions 1-3, answer each one for the case of a two's complement number and an unsigned number, indicating if it cannot be answered with a specific representation. 1. (15 pts) What is the largest integer…

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Bar Chart Write a program that asks the user to enter todays sales for five stores. The program should display ...

Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)

Write the example program in Figure 2.7 in actual bit patterns.

Computer Science: An Overview (13th Edition) (What's New in Computer Science)

What is the difference between the methods System.out.println and System.out.print?

Java: An Introduction to Problem Solving and Programming (8th Edition)

Knowledge Booster
Background pattern image
Computer Science
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
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Constants, Variables, Data types, Keywords in C Programming Language Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=d7tdL-ZEWdE;License: Standard YouTube License, CC-BY