Advertisement
filin

laba_5_z_1_new

Oct 20th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 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 Laba_5
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.Title = "Laba5_1";
  14.             Console.WriteLine("метод f(x), который возвращает вторую справа цифру натурального числа x. Вычислить с его помощью значение выражения z=f(a)+f(b)-f(c).");
  15.             Console.Write("Введите натурачльное число, a= ");
  16.             int a = Math.Abs(EnterInt());
  17.             Console.Write("Введите натуральное число, b= ");
  18.             int b = Math.Abs(EnterInt());
  19.             Console.Write("Введите натуральное число, c= ");
  20.             int c = Math.Abs(EnterInt());
  21.             int z = f(a) + f(b) - f(c);
  22.             Console.WriteLine("z=f(a)+f(b)-f(c) = {0}", z);
  23.             Console.ReadKey();
  24.         }
  25.         static int f(int x)
  26.         {
  27.             x %= 100;
  28.             x /= 10;
  29.             return x;
  30.         }
  31.         static int EnterInt()
  32.         {
  33.             int value;
  34.             bool result = false;
  35.             result = int.TryParse(Console.ReadLine(), out value);
  36.             if (result == false)
  37.             {
  38.                 do
  39.                 {
  40.                     Console.Write("Некорректные данные. Введите заново: ");
  41.                     result = int.TryParse(Console.ReadLine(), out value);
  42.                 }
  43.                 while (!result);
  44.             }
  45.             return value;
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement