₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,326,670 members, 8,427,530 topics. Date: Tuesday, 16 June 2026 at 06:38 AM

Toggle theme

Help! C++ - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingHelp! C++ (2029 Views)

1 Reply (Go Down)

Help! C++ by escobar07(op): 9:47pm On Mar 12, 2012
Write a program that inputs a five-digit integer, separates the integer into its individual digits and prints the digits separated from one another by spaces.(please use the integer and modulus operators). For example, 45678 should print: 4 5 6 7 8 9. Thanks.
Re: Help! C++ by escobar07(op): 12:37pm On Mar 13, 2012
Guys, pls help me out on this one na. cant believe i haven't the solution up till now. i know its not going to take more than 12 lines of codes, but mysteriously, i cant solve it. i'll be waiting sha.
Re: Help! C++ by okeyxyz(m): 4:22pm On Mar 13, 2012
take the number in as input
convert number to a string\array
do a for() control statement to print each digit and space.
finito!!!
Re: Help! C++ by escobar07(op):
okeyxyz: take the number in as input
convert number to a string\array
do a for() control statement to print each digit and space.
finito!!!
Thanks, but am not even allowed to use arrays or strings, just integer integer division and modulus operators.
Re: Help! C++ by okeyxyz(m):
1
Re: Help! C++ by Kobojunkie: 3:02pm On Mar 14, 2012
@Poster, take the number, if you expect only 5 digit length all the time, then you consider the following

Integer 45678/10000 = 4 and 45678 mod 10000 = 5678.
Integer 5678/1000 = 5 and 5678 mod 1000 = 678.
Integer 678/100 = 6 and 678 mod 100 = 78
Integer 78/10 = 7 and 78 mod 10 = 8.



Now if you have variable length input digit, then you can, as someone suggested, using the String length function, figure out the length of the integer passed in, and then compute the power of 10 to work from.

Kai!! I essentially did all the work for you.
Re: Help! C++ by escobar07(op): 5:17pm On Mar 14, 2012
Kobojunkie: @Poster, take the number, if you expect only 5 digit length all the time, then you consider the following

Integer 45678/10000 = 4 and 45678 mod 10000 = 5678.
Integer 5678/1000 = 5 and 5678 mod 1000 = 678.
Integer 678/100 = 6 and 678 mod 100 = 78
Integer 78/10 = 7 and 78 mod 10 = 8.



Now if you have variable length input digit, then you can, as someone suggested, using the String length function, figure out the length of the integer passed in, and then compute the power of 10 to work from.

Kai!! I essentially did all the work for you.
Gosh!Brilliant!.Only that you made me look silly.lol.Thanks anyway
1 Reply

Help: C Language And MPI ? (urgent Plz)Female Programmer Here: Please Help (c Language)Urgent! Plz Help - C Programming Problem234

Please Help With This Fortran AssignmentCome Join Us!! Let's Build The Best Data Analytics Firm In NigeriaWhats The Lowest Salary You Have Ever Been Offered As A Developer?