Question

You are given an array named digits of digitCapacity that holds the individual digits of a very large number in such a way th
0 0
Add a comment Improve this question Transcribed image text
Answer #1
while( digits[digitNumber-1] == 0)
{
        digitNumber--;
}

This segment is correct . Let say we have 11111110000000 as the array . Then suppose digitNumber is holding the 9th position (0-based index) . But originally it should be holding 6th position as after that all the values are zero. so going by this code whenever we have 0 value at digitNumber index we will decrease it's position(so to bring the digitNumber at its correct place) . After 3 loops we will have digitNumber at 6th position as required.

In the 5th segment we will not reach the correct position as it checking the value one less than it so digitNumber will stop at one place ahead of it .

In the 6th segment we are not checking the values uptill the msb instead we are getting towards the farther end of the array which is of no use and have leading zeroes.

In the 2nd segment , we are checking from the farthest end of the array which sometimes may have digitNumber at the place but not all times . so we should just start checking from the place currently hold by the digitNumber and not some other place.

Add a comment
Know the answer?
Add Answer to:
You are given an array named digits of digitCapacity that holds the individual digits of a...
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
  • Consider the problem where you are given an array of n digits [di] and a positive...

    Consider the problem where you are given an array of n digits [di] and a positive integer b, and you need to compute the value of the number in that base. In general, you need to compute For example: (1011)2 = 1(1) + 1(2) + 0(4) + 1(8) = 11; (1021)3 = 1(1) + 2(3) + 0(9) + 1(27) = 34, and (1023)4 = 3(1) + 2(4) + 0(16) + 1(64) = 75. In these examples, I give the digits...

  • What does the following code segment do to the array a[], given that the current_sizevariable holds...

    What does the following code segment do to the array a[], given that the current_sizevariable holds the number of valid elements currently in the array? int element = 0; current_size++; for (int i = current_size - 1; i > pos; i--) { a[i] = a[i - 1]; } a[pos] = element; It shifts all the array elements one position to the left (lower index). It shifts all the array elements one position to the right (higher index). It removes the...

  • Write a python program write a function numDigits(num) which counts the digits in int num. Answer...

    Write a python program write a function numDigits(num) which counts the digits in int num. Answer code is given in the Answer tab (and starting code), which converts num to a str, then uses the len() function to count and return the number of digits. Note that this does NOT work correctly for num < 0. (Try it and see.) Fix this in two different ways, by creating new functions numDigits2(num) and numDigits3(num) that each return the correct number of...

  • In Java Write a method named addDigits which accepts two inputs, num and index. The first...

    In Java Write a method named addDigits which accepts two inputs, num and index. The first input parameter num is a 4-digit positive integer and index is an int value which refers to a digit that the summation should start from. For example if the given num is 2345 and the index is 1, starting from the second digit, the result of 12 is returned which is the sum of 3, 4, and 5. If the num is not a...

  • Java Project 1. The largest positive integer of type int is 2,147,483,647. Another integer type, long,...

    Java Project 1. The largest positive integer of type int is 2,147,483,647. Another integer type, long, represents integers up to 9,223,372,036,854,775,807. Imagine that you want to represent even larger integers. For example, cryptography uses integers having more than 100 digits. Design and implement a class Huge of very large nonnegative integers. The largest integer should contain at least 30 digits. Use a deque to represent the value of an integer. Provide operations for the class that * Set the value...

  • In this lab, you will create one class named ArrayFun.java which will contain a main method...

    In this lab, you will create one class named ArrayFun.java which will contain a main method and 4 static methods that will be called from the main method. The process for your main method will be as follows: Declare and create a Scanner object to read from the keyboard Declare and create an array that will hold up to 100 integers Declare a variable to keep track of the number of integers currently in the array Call the fillArray method...

  • The place values for the eight binary digits used in IPv4 addressing are as follows: 128,...

    The place values for the eight binary digits used in IPv4 addressing are as follows: 128, 64, 32, 16, 8, 4, 2, 1. Expand this range to include an additional four bits. Do this by recording the place values for 211, 210, 29, and 28. 1111 Express the decimal value 2001 in binary by placing 1s in the binary positions requiring the addition of the corresponding place value. Place 0s in the binary positions where the corresponding place value should...

  • Validating Credit Card Numbers Write a program named Creditcard.java that prompts the user for a credit...

    Validating Credit Card Numbers Write a program named Creditcard.java that prompts the user for a credit card number and determines whether it is valid or not. (Much of this assignment is taken from exercise 6.31 in the book) Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits, and must start with: 4 for Visa cards 5 for Master cards 6 for Discover cards 37 for American Express cards The algorithm for determining...

  • (use only variables, expression, conditional statement and loop of c programming) ***C programming** int sum_of_cubes(int n)...

    (use only variables, expression, conditional statement and loop of c programming) ***C programming** int sum_of_cubes(int n) { } int quadrant(int x, int y) { } int num_occurrences_of_digit(long num, int digit) { return 0; } 3.1 int sum_of_cubes(int n) This function should return the sum of the cubes of the first n integers. For example, if n is 4, it should return 13 +23+ 39 +4°. There is a simple formula for the result: 3x = ((n + 1)) = +...

  • Write a program that instantiates an array of integers named scores. Let the size of the...

    Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...

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
ADVERTISEMENT