阵列科 - 什么是将存储阵列中的两个号码最好的方法是什么? [英] Array Division - What is the best way to divide two numbers stored in an array?

查看:156
本文介绍了阵列科 - 什么是将存储阵列中的两个号码最好的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数组(被除数,除数):

 红利[] = {1,2,0,9,8,7,5,6,6};
除数[] = {9,8};
 

我需要的结果(股息/除数)为:

 商[] = {1,2,3,4,5,6,7};
 

我这样做是使用数组加减:

  • 1的分红减去除数,直到红利变为0比除数少,每次递增商,

但它需要大量的时间。有没有更好的方式来做到这一点?

解决方案
  

有没有更好的方式来做到这一点?

您可以使用长除法

I have two arrays (dividend, divisor):

dividend[] = {1,2,0,9,8,7,5,6,6};
divisor[] = {9,8};

I need the result (dividend/divisor) as:

quotient[] = {1,2,3,4,5,6,7};

I did this using array subtraction:

  • subtract divisor from dividend until dividend becomes 0 or less than divisor, each time incrementing quotient by 1,

but it takes a huge time. Is there a better way to do this?

解决方案

Is there a better way to do this?

You can use long division.

这篇关于阵列科 - 什么是将存储阵列中的两个号码最好的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆