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

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 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;
}
Enter a number: 56
five six
Want to see more full solutions like this?
Chapter 5 Solutions
Programming in C
Additional Engineering Textbook Solutions
Starting Out with Python (4th Edition)
Electric Circuits. (11th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
- Capsim Team PowerPoint Presentations - Slide Title: Key LearningsWhat were the key learnings that you discovered as a team through your Capsim simulation?arrow_forwardWrite the SQL code that permits to implement the tables: Student and Transcript. NB: Add the constraints on the attributes – keys and other.arrow_forwardDraw an ERD that will involve the entity types: Professor, Student, Department and Course. Be sure to add relationship types, key attributes, attributes and multiplicity on the ERD.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT



