function函数求立方,定义一个函数计算一个数的立方
写一个函数,求a到b的立方和
form action="" name="caculat"
起始:input type="text" name="start"
结束:input type="text" name="end"
结果:input type="text" name="result"
input type="submit" name="sub" onClick="caculat();"
/form
script language="javascript"
!--
function caculat(){
var start,end,result;
result=0;
start=document.caculat.start.value;
end=document.caculat.end.value;
for(i=start;i=end;i++){
result+=i*i*i;
}
document.caculat.result.value=result;
}
//--
/script
编写函数fun,函数的功能是:求一个四位数的各位数字的立方和(用文本框输入一个四位数
Private Function Fun(Num?As Long) As Long
Dim i As Integer, he As Long
For i = 1 To Len(CStr(Num))
he = he + Val(Mid(CStr(Num), i, 1)) ^ 3
Next i
Fun = he
End?Function
调用方法举例
Dim j As Long, c As Long
j = InputBox("请输入一个数,计算各个位数的立方和", "计算立方和")
c = Fun(j)
MsgBox j "这个数的各个位数的立方和是" c
扩展资料:
二次编程:
#includestdio.h
#define?N?4
#define?M?3
int?fun(int?array[N][M],int?flag){?int?max,i,j,Row,Col;
max=array[0][0];
Row=0;
?Col=0;
for(i=0;iN;i++)
{
for(j=0;jM;j++)
if(maxarray[i][j])
???{????max=array[i][j];
Row=i;
Col=j;
???}?}
if(flag==0)
return?max;
?else?if(flag==1)?return?Row;?else?????return?Col;}void?main()
{
int?Row,Col,max,i,j;
?int?array[N][M]={1,2,3,4,15,6,12,18,9,10,11,2};
max=fun(array,0);
Row=fun(array,1);
?Col=fun(array,2);?printf("max=%d,Row=%d,Col=%d\n",max,Row,Col);}
参考资料来源:百度百科-函数
菜鸟求助:请编写函数计算a到b的立方和,并举例调用,调用时a、b分别为3和6。
%for matlab
function y=fun(a,b)
x=a:b;
y=sum(x.^3);
%-------保存为fun.m文件
%-----在命令窗口调用
fun(3,6)
用vb编写函数fun,函数的功能是:求一个四位数的各位数的立方和
我给你写了个函数Fun ,不管是几位数都能求出这个数的各个位数的立方和
Private Function Fun(Num As Long) As Long
Dim i As Integer, he As Long
For i = 1 To Len(CStr(Num))
he = he + Val(Mid(CStr(Num), i, 1)) ^ 3
Next i
Fun = he
End Function
'调用方法举例
Dim j As Long, c As Long
j = InputBox("请输入一个数,计算各个位数的立方和", "计算立方和")
c = Fun(j)
MsgBox j "这个数的各个位数的立方和是" c
fun 一个四编写函数fun,函数的功能是:求一个四位数的各位数字的立方和(用文本框输入一个四位数)
Private Function Fun(Num?As Long) As Long
Dim i As Integer, he As Long
For i = 1 To Len(CStr(Num))
he = he + Val(Mid(CStr(Num), i, 1)) ^ 3
Next i
Fun = he
End?Function
调用方法举例
Dim j As Long, c As Long
j = InputBox("请输入一个数,计算各个位数的立方和", "计算立方和")
c = Fun(j)
MsgBox j "这个数的各个位数的立方和是" c
扩展资料:
二次编程:
#includestdio.h
#define?N?4
#define?M?3
int?fun(int?array[N][M],int?flag){?int?max,i,j,Row,Col;
max=array[0][0];
Row=0;
?Col=0;
for(i=0;iN;i++)
{
for(j=0;jM;j++)
if(maxarray[i][j])
???{????max=array[i][j];
Row=i;
Col=j;
???}?}
if(flag==0)
return?max;
?else?if(flag==1)?return?Row;?else?????return?Col;}void?main()
{
int?Row,Col,max,i,j;
?int?array[N][M]={1,2,3,4,15,6,12,18,9,10,11,2};
max=fun(array,0);
Row=fun(array,1);
?Col=fun(array,2);?printf("max=%d,Row=%d,Col=%d\n",max,Row,Col);}
参考资料来源:百度百科-函数