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 need help in explaining how I can demonstrate how the Laplace & Inverse transformations behaves in MATLAB transformation (ex: LIke in graph or something else)
You have made the Web solution with Node.js. please let me know what problems and benefits I would experience while making the Web solution here, as compared to any other Web solution you have developed in the past. what problems and benefits/things to keep in mind as someone just learning
PHP is the server-side scripting language. MySQL is used with PHP to store all the data. EXPLAIN in details how to install and run the PHP/MySQL on your computer. List the issues and challenges I may encounter while making this set-up?  why I asked: I currently have issues logging into http://localhost/phpmyadmin/ and I tried using the command prompt in administrator to reset the password but I got the error LOCALHOST PORT not found.

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.
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