Skip to content

Instantly share code, notes, and snippets.

@pashagray
Last active February 5, 2025 07:42
Show Gist options
  • Save pashagray/cd4a0e27793ccb20eefc8255101940ba to your computer and use it in GitHub Desktop.
Save pashagray/cd4a0e27793ccb20eefc8255101940ba to your computer and use it in GitHub Desktop.
using System;
using System.Globalization;
namespace ConsoleApp
{
internal class Program
{
static void Main(string[] args)
{
// Объявить и проинициализировать 10 переменных. Среди них обязательно должны быть int, float, string и char.
int simpleNumber = 5;
float floatNumber = 5.5f;
string text = "Hello World";
char alpha = 'A';
// Наведите и проинициализируйте отдельно int и float переменные и попробуйте присвоить интовой переменной, переменную типа float
float floatNumberToConvert = 5.5f;
int resultFromFloat;
resultFromFloat = (int)floatNumberToConvert;
// Заведите строковую переменную, проинициализируйте ее следующей строкой “1234.10”, далее создайте float переменную и попробуйте в нее распарсить данную строку
string stringNumber = "1234.10";
float resultFromString;
resultFromString = float.Parse(stringNumber, CultureInfo.InvariantCulture);
}
}
}
using System;
using System.Globalization;
namespace ConsoleApp
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello my dear friend!");
Console.Write("What is your name?: ");
string name = Console.ReadLine();
Console.Write("How old are you?: ");
int age = int.Parse(Console.ReadLine());
Console.WriteLine("Great! Here is some information about you:");
Console.Write("Name: ");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(name);
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Age: ");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(age);
Console.BackgroundColor = ConsoleColor.DarkCyan;
Console.WriteLine($"Farewell, {name}!");
}
}
}
using System;
using System.Globalization;
namespace ConsoleApp
{
internal class Program
{
static void Main(string[] args)
{
// From user input
float storageLength;
float storageWidth;
float itemArea;
// Get user input
Console.Write("Enter the length of the storage unit in meters: ");
storageLength = float.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
Console.Write("Enter the width of the storage unit in meters: ");
storageWidth = float.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
Console.Write("Enter the area of the item in square meters: ");
itemArea = float.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
// Calculate the storage area
float storageArea = storageLength * storageWidth;
// Calculate the number of items that can fit in the storage unit
int numberOfItems = (int)(storageArea / itemArea);
// Output the result
Console.WriteLine($"The storage unit can hold up to {numberOfItems} items.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment