
Alguien me puede ayudar a traducir un codigo de c# a c++?
Publicado por Daniel (1 intervención) el 03/06/2020 01:20:50
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Text;
namespace MulitplyPolinomy
{
class Program
{
static void Main(string[] args)
{
// (x^2 + 2x -3)
var a = new double[] { -3, 2, 1 };
// (x+2)
var b = new double[] { 2, 1 };
var m = Multiply(a, b);
Console.WriteLine(PolinomyToString(m));
}
static double[] Multiply(double[] a, double[] b)
{
var result = new double[a.Length + b.Length - 1];
for (int i = 0; i < a.Length; i++)
{
for (int j = 0; j < b.Length; j++)
{
result[i + j] += a[i] * b[j];
}
}
return result;
}
static string PolinomyToString(double[] p)
{
var sb = new StringBuilder();
for (int i = 0; i < p.Length; i++)
{
if (i > 0) sb.Append(" + ");
sb.Append(p[i].ToString());
if (i > 0) sb.Append("x^").Append(i.ToString());
}
return sb.ToString();
}
}
}
//Necesito traducir este codigo de C# a C++
Valora esta pregunta


0