MuffinMonster

Class Task 7#

Oct 8th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int num, x, y, z = 0;
  14.             Console.WriteLine("Enter a number");
  15.             num = int.Parse(Console.ReadLine());
  16.             Console.WriteLine("Enter a digit");
  17.             x = int.Parse(Console.ReadLine());
  18.             while (x < 0 || x > 9)
  19.             {
  20.                 x = int.Parse(Console.ReadLine());
  21.             }
  22.             while (num > 0)
  23.             {
  24.                 y = num;
  25.                 y = y % 10;
  26.                 if (y == x)
  27.                 {
  28.                     z++;
  29.                 }
  30.                 num /= 10;
  31.             }
  32.             Console.WriteLine("The digit appears " + z + " in the number");
  33.             Console.ReadKey();
  34.         }
  35.     }
  36. }
Add Comment
Please, Sign In to add comment