Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Z_4
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Title = "Laba2_4";
- Console.WriteLine("Программа выводит количество цифр числа, делящихся на 3 без остатка.");
- int count = 0;
- Console.Write("Введите число: ");
- double a = EnterDoubleForLaba2_4();
- while (a > 0)
- {
- double b = a % 10;
- a = Math.Truncate(a / 10);
- if (b % 3 == 0)
- {
- count += 1;
- }
- }
- Console.WriteLine("count= " + count);
- Console.ReadKey();
- }
- static double EnterDoubleForLaba2_4()
- {
- double value;
- bool result = false;
- string s = Console.ReadLine();
- s = s.Replace(",", string.Empty);
- result = double.TryParse(s, out value);
- if (result == false)
- {
- do
- {
- Console.Write("Некорректные данные. Введите заново: ");
- s = Console.ReadLine();
- s = s.Replace(",", string.Empty);
- result = double.TryParse(s, out value);
- }
- while (!result);
- }
- return value;
- }
- }
- }
Add Comment
Please, Sign In to add comment