filin

laba_2_z_4_new

Oct 20th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 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 Z_4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.Title = "Laba2_4";
  14.             Console.WriteLine("Программа выводит количество цифр числа, делящихся на 3 без остатка.");
  15.             int count = 0;
  16.             Console.Write("Введите число: ");
  17.             double a = EnterDoubleForLaba2_4();
  18.             while (a > 0)
  19.             {
  20.                 double b = a % 10;
  21.                 a = Math.Truncate(a / 10);
  22.                 if (b % 3 == 0)
  23.                 {
  24.                     count += 1;
  25.                 }
  26.             }
  27.             Console.WriteLine("count= " + count);
  28.             Console.ReadKey();
  29.         }
  30.         static double EnterDoubleForLaba2_4()
  31.         {
  32.             double value;
  33.             bool result = false;
  34.             string s = Console.ReadLine();
  35.             s = s.Replace(",", string.Empty);
  36.             result = double.TryParse(s, out value);
  37.             if (result == false)
  38.             {
  39.                 do
  40.                 {
  41.                     Console.Write("Некорректные данные. Введите заново: ");
  42.                     s = Console.ReadLine();
  43.                     s = s.Replace(",", string.Empty);
  44.                     result = double.TryParse(s, out value);
  45.                 }
  46.                 while (!result);
  47.             }
  48.             return value;
  49.         }
  50.     }
  51. }
Add Comment
Please, Sign In to add comment