- 8
- 0
- 约4.64千字
- 约 6页
- 2017-09-02 发布于浙江
- 举报
程序功能用递归法将一个六位整数n转换成字符串例如输
该程序中”/********N********/”的下一行中的错误,请改正。(注意:不得加行、减行、加句、减句)
1、程序功能:用递归法将一个六位整数n转换成字符串。(例如输入123456,应输出字符串“123456”。)
#includestdio.h
void itoa(long i,char *s)
{
if(i==0)
return;
/****** 1 ******/
*s = 1+i%10;
itoa(i/10,s-1);
}
void main()
{
long n;
char str[7]=;
scanf(%ld,n);
/****** 2 ******/
itoa(n,str+6);
printf(%s,str);
}
2、输入n,再输入n个点的平面坐标,然后输出那些距离坐标原点不超过5的点的坐标值。
#include stdio.h
#include math.h
#include stdlib.h
void main()
{
int i,n;
/***** 1 *****/
struct axy { float x,y; } a;
scanf(%d,n);
a=(float*) malloc(n*2*sizeof(float));
for(i=0;in;i++)
/***** 2 *****/
scanf(%f%f,a[i].x,a[i].y);
for(i=0;in;i++)
if(sqrt(a[i].x*a[i].x+a[i].y*a[i].y)=5)
printf(%f,%f\n,a[i].x,a[i].y);
}
**试题本身有错误,a=(struct axy *) malloc(n*2*sizeof(float));
3、运行时若输入a、n分别为3、6,则输出下列表达式的值:3+33+333+3333+33333+333333
#include stdio.h
void main()
{ int i,a,n; long t=0;
/********* 1 *******/
s=0;
scanf(%d%d,a,n);
for(i=1;i=n;i++) {
/******* 2 ******/
t=t*10+i;
s=s+t;
}
s=s*a;
printf(%ld\n,s);
}
4、将两个字符串连接起来。
#include stdio.h
void main()
{
char s1[80],s2[40];
int i=0,j=0;
printf(\ninput the first string:);
scanf(%s,s1);
printf(\ninput the second string:);
scanf(%s,s2);
while (s1[i] !=\0)
/****** 1 ******/
i+1;
while (s2[j] !=\0)
/****** 2 ******/
s1[++i]=s2[++j]; /* 拼接字符到s1 */
s1[i] =\0;
printf(\nnew string: %s,s1);
}
5、用选择法对10个整数按升序排序。
#include stdio.h
#define N 10
void main()
{
int i,j,min,temp;
int a[N]={5,4,3,2,1,9,8,7,6,0};
printf(\nThe array is:\n); /* 输出数组元素 */
for (i=0;iN;i++)
printf(%5d,a[i]);
for (i=0;iN-1;i++) /* 排序操作 */
{
min = i;
for (j=i+1; jN; j++)
/****** 1 ******/
if (a[min]=a[j]) min =j;
/****** 2 ******/
temp=a[min]; a[min]=a[j]; a[j]=temp; /* 数据交换
您可能关注的文档
最近下载
- 常州大学《大学英语一》2024-----2025学年期末试卷(A卷).pdf VIP
- 艾米克变频器AMK3100中文说明书使用手册.pdf
- 必背古诗词75首(可打印) .pdf VIP
- 某知名汽车维修企业员工手册范本.docx VIP
- 2025年二建水利b证考试真题及答案.docx
- 安全驾驶教育培训课件.ppt VIP
- 汽车维修车间员工职责手册.docx VIP
- 黑龙江省哈尔滨市第三中学校2025-2026学年高二上学期9月月考物理试卷.docx VIP
- 初中语文名著导读--《骆驼祥子》知识点总结归纳.docx VIP
- 实施指南(2025)《DAT 22-2015 归档文件整理规则》.pptx VIP
原创力文档

文档评论(0)