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
Write a program that asks the user to enter 2 integers of 4 digits and displays thedifferent digits as X and * if they are the same. If the user enters a number which is notof four digits, then a convenient message is displayed.
Write a program that takes a positive integer x greater than zero typed in by the user, and prints the count from x to x+9 (including this one) using printf with newline after each printed value. Example: if x=1, the program should print:
In python, write a program that receives an integer, greater than or equal to 2, from the user and prints whether that number is odd or even.

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
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