如何在不知道尺寸的情况下通过MIP中的阵列迭代?

发布于 2025-01-25 02:32:33 字数 580 浏览 0 评论 0原文

我正在研究分配,以使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文