Advertisement
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 Laba_5
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Title = "Laba5_1";
- Console.WriteLine("метод f(x), который возвращает вторую справа цифру натурального числа x. Вычислить с его помощью значение выражения z=f(a)+f(b)-f(c).");
- Console.Write("Введите натурачльное число, a= ");
- int a = Math.Abs(EnterInt());
- Console.Write("Введите натуральное число, b= ");
- int b = Math.Abs(EnterInt());
- Console.Write("Введите натуральное число, c= ");
- int c = Math.Abs(EnterInt());
- int z = f(a) + f(b) - f(c);
- Console.WriteLine("z=f(a)+f(b)-f(c) = {0}", z);
- Console.ReadKey();
- }
- static int f(int x)
- {
- x %= 100;
- x /= 10;
- return x;
- }
- static int EnterInt()
- {
- int value;
- bool result = false;
- result = int.TryParse(Console.ReadLine(), out value);
- if (result == false)
- {
- do
- {
- Console.Write("Некорректные данные. Введите заново: ");
- result = int.TryParse(Console.ReadLine(), out value);
- }
- while (!result);
- }
- return value;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement