编写一个程序,提取字符串中的数字符号。例如,程序运行后输入字符串abc123edf456gh,则输出“123456”。

编写一个程序,提取字符串中的数字符号。例如,程序运行后输入字符串abc123edf456gh,则输出“123456”。,第1张

1

Sub tq()

s = InputBox("请输入一个字符串:") '输入一个字符串,放在变量s中

n = Len(s) '第1空,求出s的长度,放在变量n中

For i = 1 To n

a = Mid(s, i, 1) '第 2 空,求字符串a

If a >= o And a <= 9 Then '第3 空,如果a的值是0到9之间的数字符号

b = b & a '第 4 空,则把它拼接到结果字符串变量b中

End If

Next i

MsgBox b '输出结果

End Sub

2

Sub 合并()

r = Rows(1)End(xlToRight)Column '求第一行列数

t = Rows(2)End(xlToRight)Column '求第二行列数

For i = 1 To t '对第二行的每个数据进行处理

a = Cells(2, i): Cells(2, i) ="" '取出第二行的一个数据

For s = r To 1 Step -1 '第 1 空,从后往前扫描

If a >= Cells(1, s) Then Exit For '第 4 空,退出本层循环

Cells(1, s + 1) = Cells(1, s) '第 2 空,移动数据

Next s

Cells(1, s + 1) = a '插入数据

r = r + 1 '第3 空,修改目标数据区长度

Next '第 5 空

End Sub

3

Sub sumSelection()

For Each x In Selection '第1空,”

s = s + x '第2空

Next

msgbox "该区域的总和为:"& s '第3空

End Sub

4

Sub Student()

n = 0

While Not(IsEmpty(Cells(n + 4, 1)))

n = n + 1 '第 1 空

Wend

m =ApplicationWorksheetFunctionRoundUp((n / 25), 0)

bs = 1

Do

SheetsAdd

ActiveSheetName = Str(bs) + "班"

Cells(1, 1) = "英语" + Str(bs) + "班名单"

Cells(2, 1) = "学号"

Cells(2, 2) = "姓名"

Cells(2, 3) = "成绩"

For i = 1 To 25

For j = 1 To 3 '第 2 空

Cells(i + 2, j) =Sheets("sheet1")Cells(i + 3 + (bs - 1) 25, j) '第3 空

Next

Next

bs = bs + 1 '第 4 空

Loop While bs <= m '第 5 空

End Sub

当然可以输出了的啊,但是在输出的时候需要进行转换的,现在提供一个十进制到任意进制的转换程序,你可以在编写程序的时候参考一下。

源程序如下:

#include<stdioh>

#include<mathh>

void main()

{

int i=0,n,j,a[20],b[20],k,c=0;

double m,x,d;

printf("请输入需要转换的数:");

scanf("%lf",&x);

printf("请输入要转换成的进制(1<N<=16):");

scanf("%d",&n);

if(x<0)

m=fabs(x);

else

m=x;

k=(int)m;//强制类型转换,可以使用k=(int)m;代替,从而更加的一目了然

while(k)//判定需要转换的数是否变为0

{

a[i++]=k%n;//取余,进行进制转换,但是顺序与正确值相反

k/=n;//转换一位之后进行相应的变化

}

if(m!=(int)m)//选择性计算,如果是整数就不用进行这一步的计算了,这样可以节约程序的运行时间

{

d=m-(int)m;//取小数部分

while(d!=0)

{

b[c]=(int)(dn);//算法为×N取整

d=dn-b[c];

c++;

if(c>=10)

break;//主要是控制小数后面万一出现无限小数的时候好跳出循环以免出现死循环

}

}

printf("转换结果为:");

if(x<0)

printf("-");

for(j=i-1;j>=0;j--)//反序输出,大于10的数字进行相应的变化

{

if(a[j]==10)

printf("A");

else

if(a[j]==11)

printf("B");

else

if(a[j]==12)

printf("C");

else

if(a[j]==13)

printf("D");

else

if(a[j]==14)

printf("E");

else

if(a[j]==15)

printf("F");

else

printf("%d",a[j]);

}

if(m!=(int)m)//选择性输出,这样可以节约输出时间和程序的运行时间

{

printf("");

for(j=0;j<c;j++)//正序输出

{

if(b[j]==10)

printf("A");

else

if(b[j]==11)

printf("B");

else

if(b[j]==12)

printf("C");

else

if(b[j]==13)

printf("D");

else

if(b[j]==14)

printf("E");

else

if(b[j]==15)

printf("F");

else

printf("%d",b[j]);

}

}

if(c>=10)//如果是无限小数则在后以省略号表示

printf("");

printf("\n");//输出换行,以使程序的输出结果美观

}

1、计算机中的所有数据都是以二进制存储的,因此字符也是以二进制存储且占用一个字节,在c语言中可以把char型当作只有一个字节的有符号整数,8位有符号,最大正值就是127了。

2、例如:可以这样使用循环的

#include <stdioh>

#include <stdlibh>

int main()

{

char c;

int i;

printf("please input a char:");

for(i='a';i<'t';i++)

printf("hello world!\n");

return 0;

}

3、你问的问题代码如下

#include <stdioh>

#include <stdlibh>

int main()

{

char c;

printf("please input a char:");

scanf("%c",&c);

printf("%c\n",c);

printf("%d\n",c);

return 0;

}

分类: 电脑/网络 >> 程序设计 >> 其他编程语言

问题描述:

用Java编写程序,根据变量n的值输出菱形美圆符号

n=9

图形如下:(*表示空格)

****$****

***$$$***

**$$$$$**

*$$$$$$$*

$$$$$$$$$

*$$$$$$$*

**$$$$$**

***$$$***

****$****

解析:

public class Stars

{

public final static int MAX=10;

static int star;

public void Stars5() 打印菱形

{

int row,space,printstar;

for(row=5,star=1;row>0;row--,star+=2)

{

for(space=0;space<row;space++)

Systemoutprint(" ");

for(printstar=0;printstar<star;printstar++)

Systemoutprint("$");

Systemoutprintln();

}

for(row=1,star=9;row<=5;row++,star-=2)

{

for(space=1;space<=row;space++)

Systemoutprint(" ");

for(printstar=0;printstar<star;printstar++)

Systemoutprint("$");

Systemoutprintln();

}

}

public static void main(String[] args)

{

Stars ss=new Stars();

ssStars5();

}

}

第一个的写法是错误的 printf 里面的%d代表一个变量,必须与后面的变量名一一对应,printf("%d",c);

printf("%d,%d",a,b);其中第一个%d代表a,第二个%d代表b ,所以如果a=1,b=2的话 那么它输出的就是1,2

#include<stdioh>

int main()

{

    printf("");

    printf("");

    printf("");

    printf("");

    printf("");

    printf("");

    printf("");

    return 0;

}

以上就是关于编写一个程序,提取字符串中的数字符号。例如,程序运行后输入字符串abc123edf456gh,则输出“123456”。全部的内容,包括:编写一个程序,提取字符串中的数字符号。例如,程序运行后输入字符串abc123edf456gh,则输出“123456”。、请问,C语言中将一个数用二进制的形式输出,用什么符号急急急!今天回答另加10分!、用C语言编写程序,输入一个字符,输出它的字符值和ASCII值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/9322439.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存