So I'm just getting started in C++ and need some help. I want to right a program that inputs a number as n and then outputs digits 0-9 based on n. Also each row adds one more number until the last number is the number of digits of n.

For example if n=8

output would be
1
12
123
1234
12345
123456
1234567
12345678

any help would be great!

Recommended Answers

What happens if n is greater than 9?

Jump to Post

What do you have so far?

Jump to Post

All 7 Replies

What happens if n is greater than 9?

What do you have so far?

if n is greater than 9 it starts over at 0
so 1234567890123 for 13

I'm not looking for a code to be written for me. I just would like to know what i should write. I think i need to use k++ and count with a "while" loop. But when i try to use them all i get is an output that is wrong like

1
2
3
4
5
6 and so on

and how do i change the count to 0-9? When i go above 9 its put "10" instead of "0".

Look up the modulus operator. Using that will help you out.

the modulus operator is mod %10. i don't understand how the mod helps though.

What is the result of 10 % 10? How can that answer be used to output the value you want?

ohh ok it just hit me thanks for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.