Question

Let n be a positive integer consisting of up to 8 digits. d8, d7, …..d1.Write a...

Let n be a positive integer consisting of up to 8 digits. d8, d7, …..d1.Write a complete C program by usiang a function, to list in one column each of the digits in number n.

The right most digit, d1, should be listed at the top of the column. Hint: If

If n is 3,407, what is the value of the digit when computed by using digit=n%10;

You can test your program for values of n equal to 172,459.

So your result must show:

9

5

4

2

7

1

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

void printDigits(long n){
    while(n!=0){
        printf("%d\n",n%10);
        n = n / 10;
    }
}

int main(){
    printDigits(172459);
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
Let n be a positive integer consisting of up to 8 digits. d8, d7, …..d1.Write 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
  • 1. We can determine how many digits a positive integer has by repeatedly dividing by 10...

    1. We can determine how many digits a positive integer has by repeatedly dividing by 10 (without keeping the remainder) until the number is less than 10, consisting of only 1 digit. We add 1 to this value for each time we divided by 10. a) Describe the algorithm in a recursive way b) Implement this recursive algorithm in C++ and test it using a main function that calls this with the values of 15, 105 and 15105. (Hint: Remember...

  • I got a C++ problem. Let n be a positive integer and let S(n) denote the...

    I got a C++ problem. Let n be a positive integer and let S(n) denote the number of divisors of n. For example, S(1)- 1, S(4)-3, S(6)-4 A positive integer p is called antiprime if S(n)くS(p) for all positive n 〈P. In other words, an antiprime is a number that has a larger number of divisors than any number smaller than itself. Given a positive integer b, your program should output the largest antiprime that is less than or equal...

  • Q18 12 Points For any positive integer n, let bn denote the number of n-digit positive...

    Q18 12 Points For any positive integer n, let bn denote the number of n-digit positive integers whose digits are all 1 or 2, and have no two consecutive digits of 1. For example, for n - 3, 121 is one such integer, but 211 is not, since it has two consecutive 1 's at the end. Find a recursive formula for the sequence {bn}. You have to fully prove your answer.

  • 1. (Integers: primes, divisibility, parity.) (a) Let n be a positive integer. Prove that two numbers...

    1. (Integers: primes, divisibility, parity.) (a) Let n be a positive integer. Prove that two numbers na +3n+6 and n2 + 2n +7 cannot be prime at the same time. (b) Find 15261527863698656776712345678%5 without using a calculator. (c) Let a be an integer number. Suppose a%2 = 1. Find all possible values of (4a +1)%6. 2. (Integers: %, =) (a) Suppose a, b, n are integer numbers and n > 0. Prove that (a+b)%n = (a%n +B%n)%n. (b) Let a,...

  • Write a C++ program to read an unknown number of integer values and find the sum...

    Write a C++ program to read an unknown number of integer values and find the sum of only negative integers. Use variable n to store the user input. Hint: Check Example6E.cpp (Lecture 6) Note: Use the "Check" button to verify your answer. You can modify your code and check until you get it right. For example: Test Input Result -11 A list of integers -10 12 1 14 -1

  • MATLAB Question: TASK 5 12 MARKS -L06N] The rounded-square-root (RSR) of a positive integer n is...

    MATLAB Question: TASK 5 12 MARKS -L06N] The rounded-square-root (RSR) of a positive integer n is defined as the square root of n rounded to the nearest integer. Adapting Heron's method to integer arithmetic allows the rounded-square-root of n to be calculated as follows. Let d be the number of digits of number n d-1 If d is odd, then Xo = 2 × 107- If d is even, then Xo-7 × 107- where xo is the starting guess for...

  • Imprecise Counting - Long Runs in Binary Strings Let n=2^k for some positive integer k and...

    Imprecise Counting - Long Runs in Binary Strings Let n=2^k for some positive integer k and consider the set Sn of all n-bit binary strings. Let c be an integer in {0,…,n−k}. Consider any j∈{1,…,n−k−c+1}. How many strings b1,…,bn∈Sn have bj,bj+1,…,bj+k+c−1=00…0? In other words, how many strings in Sn have k+c consecutive zeros beginning at position j? For each j∈{1,…,n−k+c+1}, let Xj be the subset of Sn consisting only of the strings counted in the previous question. Show that (n−k−c+1)∑(j=1)...

  • Write a program that takes a positive integer n as input from the user and displays...

    Write a program that takes a positive integer n as input from the user and displays an n by n checkerboard. (Hint: your main method could do user input then call the constructor for your GUI with n as the argument.) For example, when n = 5, there are 25 alternating white and black squares inside a square boarder. The lower right corner of the overall pattern must be white. Make sure that adjacent squares are different colors regardless of...

  • Let (,)j-0,n-1 be an arbitrary set of n integer-valued coordinates Hence the values of rj and...

    Let (,)j-0,n-1 be an arbitrary set of n integer-valued coordinates Hence the values of rj and y are integers In this question, we deine the bounding rectangle as follows 1. The rectangle has horizontal and vertical edges. 2. It is the smallest rectangle which encloses all the points (Fj, yi), j = 0, ,n-1. 3. Let the coordinates of the bounding rectangle be (uo, vo), (ui,vi), (u2, 2) and (us, vs) (u0,t0) = botton left corner (u1, v)bom right corner...

  • Output Enter base: 2 supply a list of digits separated by space: 1 0 0 1...

    Output Enter base: 2 supply a list of digits separated by space: 1 0 0 1 The value for Base = 2 and digits = 1 0 0 1 is 9 Enter base: 16 supply a list of digits separated by space: 99 All digits must be in the range [0,n) Enter base: 16 supply a list of digits separated by space: 9 9 The value for Base = 16 and digits = 9 9 is 153 Enter base: 2...

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