using System; class Resistor { double R; double maxP; public Resistor(double R, double maxP) { this.R = R; this.maxP=maxP; } public double GetCurrent(double U) { return U / R; } public double GetPower(double U) { return GetCurrent(U) * U; } public bool IsAllowedVoltage(double U){ if(GetPower(U)>maxP){return false;} return true; } public override string ToString(){ return R+" oomi "+maxP+" vatti"; } } public class ResistorRun4b { static Resistor[] Allowed(Resistor[] Rs, double U){ int Count=0; foreach(Resistor R in Rs){ if(R.IsAllowedVoltage(U)){Count++;} } Resistor[] Result=new Resistor[Count]; Count=0; foreach(Resistor R in Rs){ if(R.IsAllowedVoltage(U)){ Result[Count++]=R; } } return Result; } public static void Main(String[] args) { Resistor[] Resistors=new Resistor[3]; Resistors[0]=new Resistor(220, 0.5); Resistors[1]=new Resistor(220, 0.1); Resistors[2]=new Resistor(2200, 0.1); Resistor[] Good=Allowed(Resistors, 5); foreach(Resistor R in Good){ Console.WriteLine(R); } } }