如何在不知道尺寸的情况下通过MIP中的阵列迭代?
我正在研究分配,以使用MIPS中的循环和功能来计算多项式。基本上,想法是重新创建此Java代码:
public static void getPolynomial(int n, int x[], int c[] ) {
for (int i = 0; i < n; i++) {
System.out.println( "p(" + x[i] + ") = " + calcPoly(c, x[i]) );
}
}
其中n是数组的大小,x []是多项式的参数(x vals)数组,而C []是系数的数组。在给定系数的阵列和电流 x值的情况下,计算应计算多项式。
我对循环/函数有一个粗略的了解,所以我认为我这样做给定的尺寸(例如,如果我知道阵列大小为3,我可以编写calcpoly,以便它计算出第三功率多项式)。但是我们必须使用不同尺寸的阵列测试程序,这意味着Calcpoly需要某种循环吗?
给定的calcpoly(c,x [i]))
仅在c []和x [i]中传递,如何在calcpoly中获得c []的大小?还是我以错误的方式考虑这一点?我只是不知道如何进行。
I'm working on an assignment to calculate a polynomial using loops and functions in MIPS. Basically the idea is to recreate this Java code:
public static void getPolynomial(int n, int x[], int c[] ) {
for (int i = 0; i < n; i++) {
System.out.println( "p(" + x[i] + ") = " + calcPoly(c, x[i]) );
}
}
where n is the size of the array, x[] is an array of arguments (x vals) for the polynomial, and c[] is an array of coefficients. calcPoly should calculate the polynomial given the array of coefficients and the current x-value.
I have a rough understanding of loops/functions so I think I do this given hard-coded sizes (like if I know the array size is 3, I could write calcPoly so that it calculates a 3rd power polynomial). But we have to test the program using different sized arrays, which means calcPoly will need some kind of loop right?
Given calcPoly(c, x[i]) )
is only passing in c[] and x[i], how would I get the size of c[] within calcPoly? Or am I thinking about this the wrong way? I just have no idea how to proceed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论