EBK DATA STRUCTURES AND ALGORITHMS IN C
EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
bartleby

Concept explainers

Question
Book Icon
Chapter 4, Problem 2PA
Program Plan Intro

Program to convert a decimal number into any base between “2” and “9”:

Program Plan:

  • In “main()” function
    • Declare variables “stackk1” for stack, “base_to” for base to which convert and “numm” for number in decimal to be convert.
    • Read values for “base_to” and “numm” from user.
    • If base is between “2” and “9” and “numm” is greater than “0”,
      • Push the value of “numm” mod “base_to” into stack “stackk1”.
      • Then Divide “numm” by “base_to” and take this value as next “numm”.
      • Continue above two steps till “numm” becomes “0”.
    • Pop all numbers from “stackk1” and print it till “stackk1” becomes empty.
    • If base is not between “2” and “9”, print error message.

Program Plan Intro

Modified program to convert a decimal number into any base between “11” and “27”:

Program Plan:

  • In “main()” function
    • Declare variables “stackk1” for stack, “base_to” for base to which convert and “numm” for number in decimal to be convert.
    • Read values for “base_to” and “numm” from user.
    • If base is between “11” and “27” and “numm” is greater than “0”,
      • Push the value of “numm” mod “base_to” into stack “stackk1”.
      • Then Divide “numm” by “base_to” and take this value as next “numm”.
      • Continue above two steps till “numm” becomes “0”.
    • Pop each number “ele” from “stackk1”
      • If “ele” is less than or equal to “9”, print itself.
      • If “ele” is greater than “9” and less than “27”, print character corresponding to ASCII value of “ele+55”
    • If base is not between “11” and “27”, print error message.

Blurred answer
Students have asked these similar questions
what is a feature in the Windows Server Security Compliance Toolkit, thank you.
You will write a program that allows the user to keep track of college locations and details about each location. To begin you will create a College python class that keeps track of the csollege's unique id number, name, address, phone number, maximum students, and average tuition cost. Once you have built the College class, you will write a program that stores College objects in a dictionary while using the College's unique id number as the key. The program should display a menu in this order that lets the user: 1) Add a new College 2) Look up a College 4) Delete an existing College 5) Change an existing College's name, address, phone number, maximum guests, and average tuition cost. 6) Exit the program
Show all the work
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
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning