VB编程:输入一合法的3位正整数,先后逆序输出并显示。如:输入“128”,输出“821”
假如:输入数字的 TextBox 控件名称为 txtNum1,输出用 TextBox 的名称为 txtNum2
1、判断 txtNum1 是否为数字的程序如下
If Trim(txtNum1) = "" Then Exit Sub
If Not IsNumeric(txtNum1) Then
MsgBox "请输入数字!"
txtNum1.SetFocus
End If
2、实现逆序的程序如下
Dim maxNum As Long
Dim i As Long
Dim strN1 As String
Dim strN2 As String
maxNum = Len(Trim(txtNum1))
strN1 = Str(Trim(txtNum1))
For i = maxNum + 1 To 2 Step -1
strN2 = strN2 + Mid$(strN1, i, 1)
Next
txtNum2 = strN2
在实现“逆序”程序中,我是把输入内容按字符串进行处理的,原因主要是
(1)、不知道输入数字长度的大小,
(2)、如果数字最后一位是0的话,也能明确看到结果。
3、如果你确定输入是三位数字的话,直接转换:
txtNum2 = (txtNum1 Mod 10) * 100 + ((txtNum1 Mod 100) \ 10) * 10 + (txtNum1 \ 100)
希望对你有参考价值...
数字逆序法:
Private Sub Form_Click()Dim x As IntegerDim n1 As Integer, n2 As Integer, n3 As IntegerRandomizex = Int(Rnd * 900) + 100n1 = x \ 100n2 = (x Mod 100) \ 10n3 = x Mod 10Print x, n3 * 100 + n2 * 10 + n1End Sub字符串逆序法:
Private Sub Form_Click()Dim x As IntegerDim n1 As String, n2 As String, n3 As StringRandomizex = Int(Rnd * 900) + 100n1 = Left(x, 1)n2 = Mid(x, 2, 1)n3 = Right(x, 1)Print x, Val(n3 & n2 & n1)End Sub补充一种最简单的直接函数逆序法:
Private Sub Form_Click()Dim x As IntegerRandomizex = Int(Rnd * 900) + 100Print x, Val(StrReverse(x))End Sub
注意只是用第一行第一列的单元格说明,代码如下:
Private Sub CommandButton1_Click()
Dim i As Integer
Dim s As String
s = ActiveSheet.Cells(1, 1)
If IsNumeric(s) = True Then
s = StrReverse(s)
MsgBox s
'或者 ActiveSheet.Cells(1, 1)= s
Else
MsgBox "Is not Numeric"
End If
End Sub
供参考。朋友。有疑请追问。
Private Sub Form_Click()
Dim s As String
s = Text1
If IsNumeric(s) Then
Text1 = StrReverse(s)
Else
MsgBox "输入了非数字字符!"
Text1 = ""
End If
End Sub
VB我没用过,不过如果你能懂c语言或者C#可以帮你写一个。
c语言编程题 输入一字符串,判断该字符串是否为回文。
include <stdio.h> include<stdlib.h> int main(){ char a[100];int i=0,j=0;printf("请输入字符串:\\n");gets(a);while(a[i]!='\\0')i++;i--;for(;j<=i;i--,j++){ if(a[i]!=a[j]){ break;} } if(j<=i){ printf("不是回文串\\n",a);} else { printf("是...
编程:输入一个3位整数,符号位保持不动,数字以反序的方式输出。 如:输 ...
include <stdio.h> include <math.h> void main (){ int a,b,c,d;scanf ("%d",&a);if (a>= 0){ b= a\/100;c= (a%100) \/10;d=a%10;printf ("%d", 100*d+10*c+b);} else { b= -a\/100; \/\/添加一个减号 c= (-a%100) \/10;\/\/这里也加了 d=-a%10; ...
编程,输入一个10进制正整数,然后输出它所对应的八进制数.
可以参考下面的代码:include <stdio.h> int main(int argc, char* argv[]){ int num;scanf("%d",&num);printf("%o",num);return 0;}
编程实现;从键盘输入一个大写字母,输出该字母及其对应的ASCII码值...
include <stdio.h> void main(){ char c;printf("请输入一个大写字母:\\n");scanf("%c",&c);printf("您输入的大写字母是%c\\n其对应的ASCII码值是%d\\n",c,c);printf("小写字母是%c\\n其对应的ASCII码值是%d\\n",c+32,c+32);} ...
编程实现:从键盘任意输入一个三位正整数,将该数分解成个位、十位、百 ...
include<stdio.h> int main(){ int n,k=0;int a[11]={0};scanf("%d",&n);while(n){ a[k++]=n%10;\/\/提取各个位上的数,储存在数组a中 n\/=10;} for(int i=0;i<k;i++)\/\/冒泡排序 for(int j=0;j<k-i-1;j++)if(a[j]>a[j+1]){ int t;t=a[j];a[j]=a[...
编程实现:输入整数a和b,如果a能被b整除,就输出算式和商,否则输出算式...
include <stdio.h>int main(){int a,b; scanf("%d%d",&a,&b); printf("%d\/%d=%d",a,b,a\/b); if(a%b)printf("...%d",a%b); return 0;}
编程,输入一个以回车键结束的字符串,将其中的大写字母用字母表中的...
include "stdio.h"int main(void){ char str[80];int i;printf("Input a string:");scanf("%d", &repeat);getchar();for(ri = 1; ri <= repeat; ri++){ i = 0;while((ch = getchar()) != '\\n'){ str[i] = ch;i++;} str[i] = 0;for(i = 0; str[i] != 0...
VB编程 输入一元二次方程的系数a,b,c判断解得情况,
我给你关键代码:dim a,b,c,dt,x1,x2 as single dt=b*b-4*a*c if dt>=0 then if dt=0 then msgbox("有一解")x1=-(b\/(2*a))msgbox("x1=x2=" & x1)else msgbox("有两解")x1=(-b+sqrt(dt))\/2*a x2=(-b-sqrt(dt))\/2*a msgbox("x1=" & x1 & ",x2=" & ...
C语言编程:输入一个字符和字符串,删除字符串中和输入字符相同的所有字符...
include<stdio.h> include<string.h> define LEN 100 void delete_same(char * str,char ch){ int i=0;for(i=0;str[i]!=0;i++){ if(str[i]==ch){ strcpy(str+i,str+i+1);\/*删除相同元素*\/ } i--;} } void main(){ char ch;char str[LEN];printf("Please input the ...
从键盘输入一个字符a和b,试编程实现在字符串a中的最大元素后边插入字符...
22 strcpy(&temp[index+1],b);23 strcpy(&temp[index+n+1],&a[index+1]);24 if(strlen(temp)<=126)25 strcpy(a,temp);26 else 27 strcpy(a,temp);28 a[127]='\\0';29 printf("the result is:\\n");30 puts(a);31 } ...
辟闵藿胆: (1)if keycode=13 then if isnumeric(text1.text)=true then if val(text1.text)<100 or val(text1.text)>999 then msgbox "你输入的整数不合法 100-999" exit sub else msgbox "输入合法" end if end if (2) Private Sub Command1_Click() Dim a As Integer, ...
腾冲县17224843834: 求vb高手解答1、 输入一个3位正整数,并之逆序输出.例如,输入345,则输出543,完善下列程序. Private Sub Form - Click()Dim a%, b%, c%, m%M=val... - ?
辟闵藿胆:[答案] 1.a = m \100 b= (m mod 100) \10 c & b & a2. X=X + 10 Form1.Left = X3.Unload Form1 Form2.Show4.For i = 1 to 9 If s = i^3 + j^3 + k^3 then Next i
腾冲县17224843834: vb程序:输入一个三位正整数,分别计算并输出其各个数位上的字. - ?
辟闵藿胆: Private Sub Command1_Click() Do x = CInt(InputBox("请输入一个3位整数:")) Loop While x < 0 Or x > 999 a = x \ 100 b = x \ 10 Mod 10 c = x Mod 10 MsgBox (a & "+" & b & "+" & c & "=" & a + b + c) End Sub
腾冲县17224843834: VB 随机输入一个3位数正整数,然后逆序输出,产生的随机数与逆序数同时显示利用Mod跟“/”来编码 - ?
辟闵藿胆:[答案] 规定利用Mod跟“/”来编码廷垃圾的,本来两个函数就搞定了.Private Sub Command1_Click()Dim a As Integer,b As Integer,c As IntegerDim i As Integer,j As Stringi = 100 + Int(Rnd * 900)a = Int(i / 100)b = i Mo...
腾冲县17224843834: 急求vb6.0编写程序题(1)编写程序,从键盘输入一个三位的正整数,计算并输出这个三位数的逆序数,如输入581,输出185. (2)编写程序,根据从键盘输... - ?
辟闵藿胆:[答案] 1. Private Sub command1_click() Dim a As Integer, b As Integer a = CInt(InputBox("输入一个三位的正整数")) If a >= 100 And a b = (a Mod 10) * 100 + (a \ 10 Mod 10) * 10 + a \ 100 MsgBox b Else MsgBox "输入有误!" End If End Sub 2. Private ...
腾冲县17224843834: 用vb编程在文本框输入一个三位数,单击窗体后,在窗本打印输出该数的个位数,十位数和百位数 - ?
辟闵藿胆: VB内置的常用函数里就有这个功能 mid函数:比如你在text1中输入的三位数是123 a=text1.text text2.text=mid(a,1,2) 这时输出的字符是1和2,含义是从第一个字符开始的前两个字符,再比如是mid(a,1,3)意思就是从第一个开始的前三个字符,要实现你要求的功能就是text2.text=mid(a,1,1)+" "+mid(a,2,1)+" "+mid(a,3,1)
腾冲县17224843834: VB文本框中输入一个3位正整数,求各位数字之和.例如输入835,结果为16 - ?
辟闵藿胆: dim a as integer dim s as integer a = val(text1.text) for i = 1 to 3 s = s + a mod 10 a = a \ 10 next i label1.caption = str(s)
腾冲县17224843834: 用VB语言编写程序:输入一个正整数,判断该数是否是素数. - ?
辟闵藿胆: Private Sub Command1_Click()Dim N As Long, Flags As BooleanN = Val(Text1.Text)Flags = TrueFor i = 2 To Sqr(N)If N Mod i = 0 ThenFlags = FalseExit ForEnd IfNextMsgBox N & IIf(Flags, "", "不") & "是一个素数"End Sub
腾冲县17224843834: vb编程实现:随机产生一个3位正整数,逆序输出. - ?
辟闵藿胆: Private Sub Form_Load()Dim i As IntegerDim temp As IntegerDim result As StringRandomizeFor i = 1 To 3temp = Rnd * 10If temp = 10 Then temp = 1result = result & Trim(Str(temp))NextPrint "随机数:" & resultPrint "反转后:" & StrReverse(result) End Sub
腾冲县17224843834: VB 中如何输如1个三位整数,如下图输出 百位,十位, 个位 - ?
辟闵藿胆: 这太简单了 private sub command1_click() dim a as integer a=val(text1.text) label1.caption=a \ 100 '百位 label2.caption=a \ 10 mod 10 label3.caption=a mod 10 end sub 谢谢!