Using System; using System.Linq; using System.Collections; using System.Collections.Generic;
// задачи на c# курсовая работа дан целочисленный массив размера n вывести все содержащиеся четные числа в порядке убывания
namespace NoNamespace { internal class Program {
private static void Main() { Console.WriteLine("Введите размерность массива"); var n = Convert.ToInt32(Console.ReadLine()); var mas = new int[n]; var r = new Random();
Console.WriteLine(); for(var i = 0; i < mas.Length; i++){ mas[i] = r.Next(-50, 50); Console.Write(mas[i] + " "); } Console.WriteLine();
var res = GetEvenDesc(mas); for(var i = 0; i < res.Length; i++){ Console.Write(res[i] + " "); } Console.WriteLine(); }
private static int[] GetEvenDesc(int[] mas) { Array.Sort(mas, (x, y) => -x.CompareTo(y)); var evens = new List<int>(); foreach (var element in mas.Where(x => x % 2 == 0)){ evens.Add(element); } return evens.ToArray(); } } }
WriteLn('Введите три числа'); ReadLn(A,B,C); if (A<=B)and(B<=C) then Write(A,' ',B,' ',C) else if (A<=C)and(C<=B) then Write(A,' ',C,' ',B) else if (B<=A)and(A<=C) then Write(B,' ',A,' ',C) else if (B<=C)and(C<=A) then Write(B,' ',C,' ',A) else if (C<=A)and(A<=B) then Write(C,' ',A,' ',B) else if (C<=B)and(B<=A) then Write(C,' ',B,' ',A) End.
Var a,b,c,D:real; Begin Write('a = ');ReadLn(a); Write('b = ');ReadLn(b); Write('c = ');ReadLn(c); D:=b*b-4*a*c; if D>=0 then Begin WriteLn('x = ',(-b-sqrt(D))/(2*a)); WriteLn('x = ',(-b+sqrt(D))/(2*a)); End else WriteLn('Действительных корней нет') End.
var a,b,c,d,x,x1,x2:real; begin write ('a='); read (a); write ('b='); read (b); write ('c='); read (c); d:=b*b-4*a*c; if d<0 then writeln ('NO') else if d>0 then begin x1:=(-b+sqrt(d))/(2*a); x2:=(-b-sqrt(d))/(2*a); writeln ('x1=',x1:0:2,' x2=',x2:0:2) end else begin x:=-b/(2*a); writeln ('x=',x); end end.
using System.Linq;
using System.Collections;
using System.Collections.Generic;
// задачи на c# курсовая работа дан целочисленный массив размера n вывести все содержащиеся четные числа в порядке убывания
namespace NoNamespace {
internal class Program {
private static void Main() {
Console.WriteLine("Введите размерность массива");
var n = Convert.ToInt32(Console.ReadLine());
var mas = new int[n];
var r = new Random();
Console.WriteLine();
for(var i = 0; i < mas.Length; i++){
mas[i] = r.Next(-50, 50);
Console.Write(mas[i] + " ");
}
Console.WriteLine();
var res = GetEvenDesc(mas);
for(var i = 0; i < res.Length; i++){
Console.Write(res[i] + " ");
}
Console.WriteLine();
}
private static int[] GetEvenDesc(int[] mas) {
Array.Sort(mas, (x, y) => -x.CompareTo(y));
var evens = new List<int>();
foreach (var element in mas.Where(x => x % 2 == 0)){
evens.Add(element);
}
return evens.ToArray();
}
}
}