Question

Design an algorithm (code in C) that decomposes a natural number into its figures: units, tens,...

Design an algorithm (code in C) that decomposes a natural number into its figures: units, tens, hundreds ... and you store them in a table in reverse,

Empty places will be filled with zeros.

First, you need to determine the size of the table, keeping in mind that the largest natural number that can be represented is: 2 ^ 32 - 1 = 4294967295.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
int main()
{
   int table[10];
   /*max size of the table will be 10
   since largest natural number can be represnted using 10 digits*/

   int n,m,i=0,j,rem;
  
   // inializing the table with zero
   for(j=0;j<10;j++){
       table[j]=0;
   }
   printf("Enter the natural Number ");
   scanf("%d",&n);
   m=n;   //temporarily storing the value
   while(m!=0)
   {
      
       rem=m%10; // extracting each digit
       table[i]=rem; // storing the data in the array(table) which acts as a queue
      
       /* ones digit will be stored in the first of the array
       therefore we are storing the data in the reverse order*/
       i++;
       m=m/10;
       rem=0;
              
   }
   //printing the number in the reverse order
   // since we have stored the number in reverse order in the array
   //printing array from the beggining will provide us the number in the reverse form
  
   printf("\n\nNumber in reverse order\n");
   for(j=0;j<i;j++)
   {
       printf("%d",table[j]);
   }
  
   /*note
   to print the full table with all 0 also.
   in for j loop, modify the condition as j<10 since
   the size of the table is 10
   */
return 0;
}


Add a comment
Know the answer?
Add Answer to:
Design an algorithm (code in C) that decomposes a natural number into its figures: units, tens,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a c++ code and answer number 1 Homework Ch. 13 - Employee Class 30 points...

    Create a c++ code and answer number 1 Homework Ch. 13 - Employee Class 30 points Design a class named Employee that has the following attributes: * Name ID Number- (Employee's] Identification Number " Department-the name of the department where the employee works " Position-the employee's job title The class should have the following constructors: A constructor that accepts values for all the member data as arguments A constructor that accepts the following values as arguments and assigns them to...

  • Stacks and Java 1. Using Java design and implement a stack on an array. Implement the...

    Stacks and Java 1. Using Java design and implement a stack on an array. Implement the following operations: push, pop, top, size, isEmpty. Make sure that your program checks whether the stack is full in the push operation, and whether the stack is empty in the pop operation. None of the built-in classes/methods/functions of Java can be used and must be user implemented. Practical application 1: Arithmetic operations. (a) Design an algorithm that takes a string, which represents an arithmetic...

  • in JAVA program.Use top-down design to design and implement a program to ask the user to...

    in JAVA program.Use top-down design to design and implement a program to ask the user to enter a list of integers, and then display to the user the mean and median of this list. You should first prompt the user to specify the length of the list of integers. For this assignment, your code should create an array of size 10, and then allow the user to specify the number of integers in their list, up to a maximum of...

  • PLEASE CODE IN C++ AND MAKE IT COPYABLE! In this project, you will design and implement...

    PLEASE CODE IN C++ AND MAKE IT COPYABLE! In this project, you will design and implement an algorithm to determine the next greater element of an element in an array in Θ(n) time, where 'n' is the number of elements in the array. You could use the Stack ADT for this purpose. The next greater element (NGE) for an element at index i in an array A is the element that occurs at index j (i < j) such that...

  • Programming Assignment 2 – RPN Calculator – Infix to Postfix Conversion and The Evaluations of the Postfix Expression. You are to design and implement and algorithm in Java, to input an Infix expressi...

    Programming Assignment 2 – RPN Calculator – Infix to Postfix Conversion and The Evaluations of the Postfix Expression. You are to design and implement and algorithm in Java, to input an Infix expression , convert to a postfix expression and finally evaluate the postfix expression… Follow the examples done during class lectures… We are used to infix notation - ”3 + 4” - where the operator is between the operands. There is also prefix notation, where the operand comes before...

  • Array Vs Symbol Table Comparison Code A) B) C) D) What is the key difference between...

    Array Vs Symbol Table Comparison Code A) B) C) D) What is the key difference between an array and a symbol table? Assume you have a bunch of objects containing information about different SER classes and need to store their data somewhere. You could use their course number as a key and then store them into either an array or symbol table - which would be better if you wanted to quickly print out all of the classes? Explain. Show...

  • Sequential Search Algorithm Python Programming Objectives ---------- * sequential search - design, analyze, implement, test, time...

    Sequential Search Algorithm Python Programming Objectives ---------- * sequential search - design, analyze, implement, test, time * continue practicing previously learned skills: algorithm analysis, graphing with theoretical prediction curves Implementation -------------- Write a function named sequential_search. It must have two parameters, a list to search and a value to search for. It must return either the index of the value within the list or -1 if the value is not found in the list. Your search function should NOT print...

  • Code in C++. Can someone make it so that the code below can be compiled? ▪...

    Code in C++. Can someone make it so that the code below can be compiled? ▪ Creating an empty queue ▪ Inserting a value ▪ Removing a value ▪ Finding the size of the queue ▪ Printing the contents of the queue ▪ Adding the contents of one queue to the end of another ▪ Merging the contents of two queues into a third, new, queue Class Attributes Your class should be implemented using a linked list and should have...

  • Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQ...

    Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...

  • Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQ...

    Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT