当前位置:网站首页>"Fundamentals of program design" Chapter 10 function and program structure 6-6 recursive implementation sequential output integer (15 points)
"Fundamentals of program design" Chapter 10 function and program structure 6-6 recursive implementation sequential output integer (15 points)
2022-07-21 11:33:00 【Cha ran o】
This question requests to realize a function , Output an integer in bit order .
Function interface definition :
void printdigits( int n );
function printdigits
Should be n
Each digit of the is printed in order from high to low , Each number is on one line .
Sample referee test procedure :
#include <stdio.h>
void printdigits( int n );
int main()
{
int n;
scanf("%d", &n);
printdigits(n);
return 0;
}
/* Your code will be embedded here */
sample input :
12345
No blank lines at the end
sample output :
1
2
3
4
5
No blank lines at the end
void printdigits( int n )
{
int i=0;
int a[100];
if(n==0) printf("0");
else
{
while(n>0)
{
a[i++]=n%10;
n/=10;
}
int m;
for(m=i-1;m>=0;m--)
{
printf("%d\n",a[m]);
}
}
}
边栏推荐
猜你喜欢
随机推荐
什么是视频内容推荐引擎?
网站资源
《程序设计基础》 第十章 函数与程序结构 6-9 十进制转换二进制 (15 分)
Development direction and problems of optaplanner
2021-9-19
[Yugong series] July 2022 go teaching course 013 constant, pointer
float的精度问题
ICASSP 2022 | 用于多模态情感识别的KS-Transformer
交叉熵损失
Wpf 多指应用开发解析
Error when wmware enables virtualization function
RichTextbox保存为图片
2021-09-16
网络安全学习(二)IP地址
2021-09-17
416. 分割等和子集
网络安全学习(一)虚拟机
2021-9-18
低资源语言的语义模糊设置中的复杂 NER
Improvement of wechat applet 24 playing music page ①