如题所述
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
扩展资料:
二次编程:
#include<stdio.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;i<N;i++)
{
for(j=0;j<M;j++)
if(max<array[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);}参考资料来源:百度百科-函数
温馨提示:答案为网友推荐,仅供参考
第1个回答 2011-06-17
public int fun(string text)
{
int result = 0;
foreach (char item in text)
{
int i = int.Parse(item.ToString());
result += i * i * i;
}
return result;
}追问
{
int result = 0;
foreach (char item in text)
{
int i = int.Parse(item.ToString());
result += i * i * i;
}
return result;
}追问
诶呀 我的作业不能像你这样交啊 我要的是具体的程序 能帮我编出来么 谢了
第2个回答 2011-06-17
function cubeSum(num){
var sum = 0;
var len = num.toString().length;
if(len == 1) return cube(num);
for(var i=0;i<len;i++){
sum += cube(parseInt(num.toString()[i]));
}
return sum;
}
function cube(num){
return num*num*num;
}
alert(cubeSum(1234));追问
var sum = 0;
var len = num.toString().length;
if(len == 1) return cube(num);
for(var i=0;i<len;i++){
sum += cube(parseInt(num.toString()[i]));
}
return sum;
}
function cube(num){
return num*num*num;
}
alert(cubeSum(1234));追问
我的作业不能像你这样交啊 我要的是具体的程序 能帮我编出来么 谢了
本回答被提问者和网友采纳