Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Write a program in C# Sharp to display the individual digits of a given number using recursion.
- Input any number : 1234
- The digits in the number 1234 are : 1 2 3 4*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication4
- {
- class Program
- {
- public static int GetUserNumber()
- {
- Console.Write("Input any number : ");
- int userNumber = Convert.ToInt32(Console.ReadLine());
- return userNumber;
- }
- public static void DisplayNumbers(int userNum) //Вывод результатов зацикливается, не доходя до 1
- {
- if (userNum % 10 >= 1)
- {
- userNum /= 10;
- DisplayNumbers(userNum);
- Console.Write(" " + userNum % 10);
- }
- else Console.Write("");
- }
- static void Main(string[] args)
- {
- int userNum = GetUserNumber();
- DisplayNumbers(userNum);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement