Skip to content

Instantly share code, notes, and snippets.

@igorLisovitskiy
Created February 14, 2019 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorLisovitskiy/8f6183a6bca381548c72d9c719613f8c to your computer and use it in GitHub Desktop.
Save igorLisovitskiy/8f6183a6bca381548c72d9c719613f8c to your computer and use it in GitHub Desktop.
using System;
namespace Andrew
{
class Program
{
public static void Count() //Задача 4
{
int a = 1;
int b = 2;
Console.WriteLine("Before");
Console.WriteLine($"{a} and {b}");
//Это норм
//int c;
//c = a;
//a = b;
//b = c;
//without 3ed
// Это не работает, но задумка правильная
//f = (f + g);
//g = (f - g);
//f = (f - g);
//Решение
a = (a + b);
b = (a - b);
a = (a - b);
Console.WriteLine("After");
Console.WriteLine($"{a} and {b}");
}
public static void ConntOnetoHundredDivon3() //задача 10
{
int sum = 0;
for (int i = 1; i <= 100; i++)
{
if (i % 3 == 0)
{
Console.Write($" {i}");
sum++;
}
}
Console.WriteLine("At All numbers of counts " + sum);
}
// Нужно исправить, сумма не вывдится посмотри в какой строке ты ее выводишь.
public static void EnternumberorOK() //задача 11
{
while (true)
{
Console.WriteLine("Input your number ");
string rez = Console.ReadLine();
if (rez == "ok")
{
Console.WriteLine("OKAY, let's go out");
break;
}
else if (rez != "ok") // Это лишнее можно без этого if
{
int result = Convert.ToInt32(rez);
int sum = 0;
while (result != 0)
{
sum += result % 10;
result /= 10;
}
Console.WriteLine(sum); //
}
else
{
Console.WriteLine("Unknown value");
}
}
}
// Вывод задачи не соответсвует требованиям, необходимо вводить произволльное число и выводить как введенноечисло! = ответ.
// ЗЫ удаляй закоченченый код когда закончил
public static void Faktorial() //задача 12
{
Console.WriteLine("Would you like to count factorial? - ");
string answer = Console.ReadLine();
if (answer == "Y")
{
//Console.WriteLine("insert your number ");
//int f = 5; //Convert.ToInt32(Console.ReadLine());
//int sum=1;
// for (int i = 5; i > 1; i--)
// {
// sum = sum * i;
// Console.WriteLine($"factorial of your number equals of {sum}");
//}
int s;
int F = 1;
for (s = 5; s > 1; s--)
F = F * s;
Console.WriteLine("Факториал 5 = " + F);
Console.ReadLine();
}
else
{
Console.WriteLine("Okay, I continue to sleep");
}
}
/*
Не нужно просить пользователя вводить число каждый раз, просто создай переменную и бери его оттуда.
Также неверно работает суммирование, сейчас это бесконечный цикл.
*/
public static void Number() // задача 13
{
Console.WriteLine("Введите число ");
int a = Convert.ToInt32(Console.ReadLine());
int count = 0;
while (a > 0)
{
a /= 10;
++count;
}
Console.WriteLine("Количество чисел " + count);
Console.WriteLine("Повторите ввод числа ");
int b = Convert.ToInt32(Console.ReadLine()), rez = 0, k = 0;
while ((k = b % 10) != 0 || b / 10 != 0) //HARD
{
rez = rez * 10 + k;
b /= 10;
}
Console.WriteLine("Invers числа " + rez);
Console.WriteLine("Повторите ввод числа ");
int a_new = Convert.ToInt32(Console.ReadLine());
int sum = 0;
// в этом цикле ошибка
while (a_new != 0)
{
sum += a_new % 10;
a /= 10;
Console.WriteLine("Sum данного числа " + sum);
}
}
static void Main(string[] args)
{
//Count(); посмотри решение
//EnternumberorOK(); исправить
//Faktorial(); исправить
//Number();исправить
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment