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 cannot program smart home automation rules from my device using a computer or phone, and I would like to know how to properly connect devices such as switches and sensors together ? Cisco Packet Tracer 1. Smart Home Automation:o Connect a temperature sensor and a fan to a home gateway.o Configure the home gateway so that the fan is activated when the temperature exceedsa set threshold (e.g., 30°C).2. WiFi Network Configuration:o Set up a wireless LAN with a unique SSID.o Enable WPA2 encryption to secure the WiFi network.o Implement MAC address filtering to allow only specific clients to connect.3. WLC Configuration:o Deploy at least two wireless access points connected to a Wireless LAN Controller(WLC).o Configure the WLC to manage the APs, broadcast the configured SSID, and applyconsistent security settings across all APs.
using r language for integration theta = integral 0 to infinity (x^4)*e^(-x^2)/2 dx (1) use the density function of standard normal distribution N(0,1) f(x) = 1/sqrt(2pi) * e^(-x^2)/2 -infinity <x<infinity as importance function and obtain an estimate theta 1 for theta set m=100 for the estimate whatt is the estimate theta 1? (2)use the density function of gamma (r=5 λ=1/2)distribution f(x)=λ^r/Γ(r) x^(r-1)e^(-λx) x>=0 as importance function and obtain an estimate theta 2 for theta set m=1000 fir the estimate what is the estimate theta2? (3) use simulation (repeat 1000 times) to estimate the variance of the estimates theta1 and theta 2 which one has smaller variance?
using r language A continuous random variable X has density function f(x)=1/56(3x^2+4x^3+5x^4).0<=x<=2 (1) secify the density g of the random variable Y you find for the acceptance rejection method. (2) what is the value of c you choose to use for the acceptance rejection method (3) use the acceptance rejection method to generate a random sample of size 1000 from the distribution of X .graph the density histogram of the sample and compare it with the density function f(x)

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