VB编写函数,求任意一个正整数各位数字之和?
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/06 09:47:10
intfun(intn){inta=n,b=0;while(a>0){b=b*10;b=b+a%10;a=a/10;}printf("%d",b);getch();return0;}或者把后三行删掉,
假设文本框为TEXT1,标签为LABEL1,函数代码如下:publicsubtestnum()dimxaslongx=cint(text1.text)ifxmod2=1thenlabel1.capti
#include#include#include/*利用辗转相除法求最大公约数*/intgcd(intn,intm){intr;if(n
Function Exchange(ByVal num As Integer) If num
#includeintsum(intn){ints=0;while(n){s+=n%10;n/=10;}returns;}intmain(void){ints=0;for(int
FunctionMax(xAsInteger,yAsInteger,zAsInteger)AsIntegerMax=IIf(x>=y,x,y)Max=IIf(Max>=z,Max,z)EndFunct
在窗体上添加一个按钮,加入如下代码“PrivateSubCommand1_Click()DimN'因为你说的是任意正整数,所以没有给变量指定变量类型DimIAsIntegerDimLAsInteger
PrivateFunctionisPrim(n%)AsBoolean'素数判断子过程Dimd%Ifn=2ThenisPrim=True:ExitFunctionFord=2ToSqr(n)IfnMod
PrivateSubCommand1_Click()n=Val(Text1.Text)Fori=1Tons=s+iNextiText2.Text=sEndSu
PrivateFunctionSUM(Fir_LAsDouble,Fir_SAsDouble,Scend_LAsDouble,Scend_SAsDouble)AsDoubleSUM=Fir_L*Fir
PrivateSubForm_Click()Dimi,n,tempn=Val(InputBox("N","",10))^3Fori=1TonStep2temp=fc(i,n)NextMsgBoxtem
voidfun(longn){intwan,qian,bai,shi,ge;//定义各数位longnixushu;//定义逆序数wan=n/10000;qian=(n-wan*10000)/1000;
'最大公约数FunctiongetGcd(num1AsLong,num2AsLong)AsLongDimiAsLongFori=IIf(num1Ifnum1Modi=0Andnum2Modi=0The
privatesubcommand1_click()dimi,j,nn=val(inputbox("n="))ifIsPrime(n)thenprintn&"是素数."elsefori=n+1ton+
clears=0input'请输入一个正整数:'toxfori=1toxifi%20&&判断i是否为奇数s=s+iendifendfor's=',sreturn(此题是求和问题,循环和用循环语句,因知
#includeintfun(intm,intn){inti,s=1;for(i=2;i
Private Sub Command1_Click()Dim i As Integer, j As Integer,&
voids(folata,folatb,folatc){folatp;p=(a+b+c)/2;S=√[p(p-a)(p-b)(p-c)];returns;}
#include//北京交通大学Lenhal//功能:计算三个正整数的最大公约数//2013/01/06main(){intfun(intaa[],intx,inty);intm,n,p,max,a[
PrivateSubCommand1_Click()a=InputBox("请输入数值")b=InputBox("请输入数值")IfVal(a)Fori=1ToVal(a)IfVal(a)Modi=0