广州黄岐桑拿按摩:给出一个正整数,编程实现:从低位到高位顺序输出每位数字,以及位数。

来源:百度文库 编辑:神马品牌网 时间:2024/05/05 05:59:10
给出一个正整数,编程实现:从低位到高位顺序输出每位数字,以及位数。
用C语言编写 TC

void myprint(int num)
{
int t=0;
do
{
printf("%d",num%10);
t++;
} while(num/=10);
printf("\nTotal:%d Digits\n",t);
}

运行示例:
input n: 8324
4 2 3 8
count=4

源码如下:

#include <stdio.h>

int main()
{
int n = 0;
int wei;
int count = 0;
int t;
int i;
printf("input n: ");
scanf("%d", &n);
t = n;
while (t)
{
count++;
wei = t % 10;
printf("%d ", wei);
t /= 10;
}
printf("\n");
printf("count=%d\n", count);

return 0;
}

不知你要什么语言的,我写了一个pascal的:

Readln(n);
i := 0;
while n > 0 do
begin
d := n mod 10;
n := n div 10;
Writeln(d);
Inc(i);
end;
Writeln('位数', i);

运用除法截断取整的算法
不断除10的倍数
算法知道了
程序自己编吧

请问要用什么语言?VB?VC?