using System;
namespace New_Project
{ public static class Program
{
public static void Main()
{
double U, R;
while (true)
{
Console.Write("U R: ");
var s = Console.ReadLine().Split(" ");
U = double.Parse(s[0]);
R = double.Parse(s[1]);
Console.WriteLine($"{U} V / {R} Ω = {U/R} A");
}
}
}
}
using System;
namespace OhmsLawCalculator
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Ohm's Law Calculator");
Console.Write("Enter the voltage (U) in volts: ");
double voltage = double.Parse(Console.ReadLine());
Console.Write("Enter the resistance (R) in ohms: ");
double resistance = double.Parse(Console.ReadLine());
double current = CalculateCurrent(voltage, resistance);
Console.WriteLine($"The current (I) is: {current} amperes");
}
static double CalculateCurrent(double voltage, double resistance)
{
return voltage / resistance;
}
}
}
using System;
class Program {
static void Main() {
var u = InputDouble("U: ");
var r = InputDouble("R: ");
var i = Current(u, r);
Console.WriteLine($"I: {i}");
Console.ReadKey();
}
static double InputDouble(string prompt) {
double value;
string? word;
do {
Console.Write(prompt);
word = Console.ReadLine();
} while (!double.TryParse(word, out value));
return value;
}
static double Current(double voltage, double resistance) {
return voltage / resistance;
}
}
пользователем значениям напряжения и тока на основе закона Ома | = U/R.