致力于计算数组中值的几何平均值
该函数应该正确计算地理平均值,但我得到一个奇怪的错误消息
#include <stdio.h>
#include <stdint.h>
#include <math.h>
extern "C"
double geomean(double myarray[], int count) ////error here, expected '(' before string constant
{
double geomean = 1;
double root = (1/(double)count);
int i;
for(i = 0; i < count; i++)
{
geomean = geomean * myarray[i];
}
geomean = pow(geomean, root);
return geomean;
}
Run Code Online (Sandbox Code Playgroud) 我在一个活动中创建一个包,然后在另一个活动中提取它
这是它在主要活动中创建的时间
//Create bundle to reference values in next class
Bundle bundle = new Bundle();
bundle.putInt("ODD", odd);
bundle.putInt("EVEN", even);
bundle.putInt("SMALL", small);
bundle.putInt("BIG", big);
//After all data has been entered and calculated, go to new page for results
Intent myIntent = new Intent();
myIntent.setClass(getBaseContext(), Results.class);
startActivity(myIntent);
//Add the bundle into myIntent for referencing variables
myIntent.putExtras(bundle);
Run Code Online (Sandbox Code Playgroud)
然后,当我提取其他活动
//Extract the bundle from the intent to use variables
Bundle bundle = getIntent().getExtras();
//Extract each value from the bundle for usage
int odd = bundle.getInt("ODD"); …Run Code Online (Sandbox Code Playgroud) ;print out division message
mov rcx, 0 ;zero out register
mov rax, [input]
mov rcx, [input2]
idiv rcx ;divide rax by rcx
mov rdi, rax ;for printing purposes
call print_int
Run Code Online (Sandbox Code Playgroud)
我似乎无法弄清楚为什么这不是分裂,我得到一个enrror"浮点异常"我使用64位机器,值是整数而不是浮点....想法?
我知道在除法发生之后,商应该是rax,剩下的应该是rdx我相信,但是现在我只是试着把手放在商上.
尝试将正数除以负数。
目前我的程序将正确划分,并且我可以正确访问其余部分。
但是当我输入一个正数除以一个负值时,它根本不会除。
我知道有一种方法可以“签名扩展”并且它会正确划分。我只是看不懂说明书
movsss $imm/%reg %reg/mem 移动,符号扩展 231 movzss $imm/%reg %reg/mem 移动,零扩展
当然那是 att 语法,我需要 intel 语法
这是我的代码
xor rdx, rdx
mov rax, [input]
mov rcx, [input2]
idiv rcx
Run Code Online (Sandbox Code Playgroud)
想法如何除以负数?
尝试将TextView设置为包含变量的特定消息.
例如
tvOddEven.setText("You have entered:", odd, "% of numbers");
Run Code Online (Sandbox Code Playgroud)
odd是一个int变量
它给了我一个错误,我不能使用这些参数.
想法?