python编程怎么输入实现:输入一个不多于5位的正整数,要求:输出它是几位数,分别输出每一位数字,按逆序输出各位数字

当前位置: >>
日 10:35:56&&分类: c++程序设计第三版谭浩强课后答案&&参与: 人&&
&给出一个不多于5位数的正整数;(1)求出它是几位数; (2)分别打印出每一位数字;& (3)按逆顺序打印出各位数,例如原有数为123,应输出321以下是此题的【c++源代码】,#include &iostream&int main (){& int indiv,ten,hundred,thousand,ten_thousand, &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& /*分别代表个位,十位,百位,千位,万位和位数*/& cout&&&enter an integer(0~99999):&;& cin&&& if (num&9999)&&&&&& place=5;& else& if (num&999)&&&&&& place=4;& else& if (num&99)&&&&&& place=3;& else& if (num&9)&&&&&& place=2;& else place=1;& cout&&&place=&&&place&&& //计算各位数字& ten_thousand=num/10000;& thousand=(int)(num-ten_thousand*1;& hundred=(int)(num-ten_thousand*10000-thousand*;& ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;& indiv=(int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);& cout&&&original order:&;& switch(place)&&& {case 5:cout&&ten_thousand&&&,&&&thousand&&&,&&&hundred&&&,&&&ten&&&,&&&indiv&&&&&& cout&&&reverse order:&;&&&& cout&&indiv&&ten&&hundred&&thousand&&ten_thousand&&&&&&&&&& case 4:cout&&thousand&&&,&&&hundred&&&,&&&ten&&&,&&&indiv&&&&&& cout&&&reverse order:&;&&&& cout&&indiv&&ten&&hundred&&thousand&&&&&&&&&& case 3:cout&&hundred&&&,&&&ten&&&,&&&indiv&&&&&& cout&&&reverse order:&;&&&& cout&&indiv&&ten&&hundred&&&&&&&&&& case 2:cout&&ten&&&,&&&indiv&&&&&& cout&&&reverse order:&;&&&& cout&&indiv&&ten&&&&&&&&&& case 1:cout&&indiv&&&&&& cout&&&reverse order:&;&&&& cout&&indiv&&&&&&& }& return 0;}&&&
本文链接:
本文标签:&&&&
-----------
相关文章 10:9:53 10:4:21 22:59:41 22:54:5 22:41:47 18:10:26 17:19:20 16:46:5 16:36:31 13:50:48
关于我们:
c++程序设计爱好者,编程新手
网站内容:
C++源码,下载,C++算法,经验
联系方式:扫二维码下载作业帮
1.75亿学生的选择
下载作业帮安装包
扫二维码下载作业帮
1.75亿学生的选择
C语言:输入一个多于5位的正整数,要求:求它是几位数,分别输出每一个数字,按逆序输出各位数字
扫二维码下载作业帮
1.75亿学生的选择
#include#define MAXN 20int main(){int n,t,k=0;int ia[MAXN];printf("请输入一个整数:");scanf("%d",&n);while(t=n%10){ia[k++]=t;n/=10;}printf("这是一个%d位数!\n",k);printf("每位数字分别是:");for(t=0;t
为您推荐:
其他类似问题
扫描下载二维码第4章 选择结构程序设计 习题 - edwardflee的博客 - 编程中国
第4章 选择结构程序设计 习题
算术运算就是数的加、减、乘、除以及乘方开方等数学运算
所谓“关系运算”就是“比较运算” 将两个数值进行比较,判断其比较的结果是否符给定的条件
4.2 C语言如何表示“真”和“假”?系统如何判断一个值的“真”和“假”?
C语言用1表示真,用0表示假
C语言判断0为假,非0为真
4.3 写出下面各逻辑表达式的值。设a=3,b=4,c=5
(1)a+b&c && b==c
(2) a || b+c && b-c
(3) !(a&b) && !c ||1
(4) !(x=a) && (y=b) && 0
(5) !(a+b)+c-1 && b+c/2
!(a+b)+c-14
4.4 a,b,c 时间:日14:24:37题目:习题4.4 有三个整数a,b,c 由键盘输入,输出其中最大的数*/# include &stdio.h&int main(){&&&&&&&&int a,b,c;&&&&int max(int a,int b,int c);&&&&&&&&printf("输入三个整数:\n");&&&&scanf("%d%d%d",&a,&b,&c);&&&&&&&&printf("其中最大的是:%d\n",max(a,b,c));&&&&&&&&return <SPAN style="COLOR: #;}int max(int a,int b,int c){&&&&int&&&&&&&&if(a&=b)&&&&{&&&&&&&&if(a&c)&&&&&&&&{&&&&&&&&&&&&max=a;&&&&&&&&}&&&&&&&&else&&&&&&&&{&&&&&&&&&&&&max=c;&&&&&&&&}&&&&}&&&&else if(b&=c)&&&&{&&&&&&&&max=b;&&&&}&&&&else&&&&{&&&&&&&&max=c;&&&&}&&&&return(max);}
4.5 10001000时间:日14:47:11题目:从键盘输入一个小于1000的正数,要求输出他的平方根(如果平方根不是整数,输出其整数部分)要求:要求在输入数据后先对其检查是否为小于1000的正数,若不是,则要求重新输入*/# include &stdio.h&# include &math.h&int main(){&&&&double&&&&&&&&printf("请输入一个小于1000的正数\n");&&&&scanf("%lf",&a);&&&&&&&&while(a&=<SPAN style="COLOR: # || a&=<SPAN style="COLOR: #00)&&&&{&&&&&&&&printf("请重新输入输入\n");&&&&&&&&scanf("%lf",&a);&&&&}&&&&&&&&printf("平方根的整数部分是:%-5.0lf\n",sqrt(a));&&&&return <SPAN style="COLOR: #;}/*在VC++6.0中的输出结果为:————————————请输入一个小于1000的正数1001请重新输入输入0请重新输入输入5平方根的整数部分是:2Press any key to continue————————————*/
4.6 y=xx&1y=2x-11&=x&10y=3x-11 (x&=10).xy时间:日15:17:52题目:有一个函数,写程序,输入x的值,输出y相应的值函数::y=x(x&1)&&&&&&&& =2x-1(1&=x&10)&&&&&&&& =3x-11 (x&=10)*/# include &stdio.h&int main(){&&&&double x,y;&&&&&&&&printf("输入x的值\n");&&&&scanf("%lf",&x);&&&&&&&&if(x&<SPAN style="COLOR: #)&&&&{&&&&&&&&y=x;&&&&}&&&&else if(<SPAN style="COLOR: #&=x && x&<SPAN style="COLOR: #)&&&&{&&&&&&&&y=<SPAN style="COLOR: #*x-<SPAN style="COLOR: #;&&&&}&&&&else&&&&{&&&&&&&&y=<SPAN style="COLOR: #*x-<SPAN style="COLOR: #;&&&&}&&&&printf("y的值是%lf\n",y);&&&&&&&&return <SPAN style="COLOR: #;}/*在VC++6.0中的输出结果为:————————————输入x的值0y的值是0.000000Press any key to continue输入x的值1y的值是1.000000Press any key to continue输入x的值10y的值是19.000000Press any key to continue————————————*/
4.7 y=-1x&0y=0x=0y=1(x&0)..
x&0y=1x&0y=0x=0y=-1elaeif
&stdio.h&int main(){&&&&int x,y;&&&&printf("enter x:");&&&&scanf("%d",&x);&&&&y=-<SPAN style="COLOR: #;&&&&if(x!=<SPAN style="COLOR: #)&&&&&&&&if(x&<SPAN style="COLOR: #)&&&&&&&&&&&&y=<SPAN style="COLOR: #;&&&&else&&&&&&&&&&&&&&&&//这样写格式不好,实际上else是与if(x&0)配对的&&&&&&&&y=<SPAN style="COLOR: #;&&&&printf("x=%d,y=%d\n",x,y);&&&&return <SPAN style="COLOR: #;}/*在VC++6.0中的输出结果为:————————————enter x:1x=1,y=1Press any key to continueenter x:0x=0,y=-1Press any key to continueenter x:-1x=-1,y=0Press any key to continue————————————*/
# include &stdio.h&int main(){&&&&int x,y;&&&&printf("enter x:");&&&&scanf("%d",&x);&&&&y=<SPAN style="COLOR: #;&&&&if(x&=<SPAN style="COLOR: #)&&&&&&&&if(x&<SPAN style="COLOR: #) y=<SPAN style="COLOR: #;&&&&else y=-<SPAN style="COLOR: #;&&&&&&&&//这样写格式不好,实际上else是与if(x&0)配对的&&&&printf("x=%d,y=%d\n",x,y);&&&&return <SPAN style="COLOR: #;}/*在VC++6.0中的输出结果为:————————————enter x:1x=1,y=1Press any key to continueenter x:0x=0,y=-1Press any key to continueenter x:-1x=-1,y=0Press any key to continue————————————*/
4.8 ’A’’B’’C’’D’’E’90A80~89B70~79C60~69D60E
/*时间:日8:32:38题目:习题4.8 给出一百分制成绩,要求输出成绩等级'A''B''C''D''E'备注:90分以上为A,80~89为B,70~79为C,60~69为D,60分以下为E*/# include &stdio.h&int main(){&&&&double&&&&&&&&do&&&&{&&&&&&&&printf("输入分数:");&&&&&&&&scanf("%lf",&score);&&&&&&&&if(score&<SPAN style="COLOR: # || score&<SPAN style="COLOR: #0)&&&&&&&&{&&&&&&&&&&&&printf("请重新");&&&&&&&&}&&&&&&&&else&&&&&&&&{&&&&&&&&&&&&break;&&&&&&&&}&&&&}&&&&while(<SPAN style="COLOR: #);&&&&&&&&switch(int(score)/<SPAN style="COLOR: #)&&&&{&&&&case <SPAN style="COLOR: #:&&&&case <SPAN style="COLOR: #:&&&&&&&&printf("等级为A\n");&&&&&&&&break;&&&&case <SPAN style="COLOR: #:&&&&&&&&printf("等级为B\n");&&&&&&&&break;&&&&case <SPAN style="COLOR: #:&&&&&&&&printf("等级为C\n");&&&&&&&&break;&&&&case <SPAN style="COLOR: #:&&&&&&&&printf("等级为D\n");&&&&&&&&break;&&&&default:&&&&&&&&printf("等级为E\n");&&&&}&&&&&&&&return <SPAN style="COLOR: #;}/*在VC++6.0中的输出结果为:————————————输入分数:101请重新输入分数:-5请重新输入分数:100等级为APress any key to continue输入分数:91.5等级为APress any key to continue输入分数:88等级为BPress any key to continue输入分数:75等级为CPress any key to continue输入分数:60等级为DPress any key to continue输入分数:59.9等级为EPress any key to continue输入分数:0等级为EPress any key to continue————————————*/
3时间:日9:19:40题目:习题4.9 给一个不多于5位的正整数要求:(1)求出它是几位数&&&&&&(2)分别输出每一位数字&&&&&&(3)按逆序输出每位数字*/# include &stdio.h&int main(){&&&&int i,j,k=<SPAN style="COLOR: #;&&&&int a[<SPAN style="COLOR: #];&&&&&&&&do&&&&{&&&&&&&&printf("输入一个正整数(1~99999):");&&&&&&&&scanf("%d",&i);&&&&&&&&if (i&=<SPAN style="COLOR: #999 && i&<SPAN style="COLOR: #)&&&&&&&&{&&&&&&&&&&&&break;&&&&&&&&}&&&&&&&&else&&&&&&&&{&&&&&&&&&&&&printf("输入超出范围,请重新");&&&&&&&&}&&&&}&&&&while(<SPAN style="COLOR: #);&&&&&&&&for(j=<SPAN style="COLOR: #; j&<SPAN style="COLOR: #; ++j)&&&&{&&&&&&&&a[j]=i%<SPAN style="COLOR: #;&&&&&&&&i/=<SPAN style="COLOR: #;&&&&&&&&if(i!=<SPAN style="COLOR: #)&&&&&&&&{&&&&&&&&&&&&++k;&&&&&&&&}&&&&}&&&&&&&&printf("这个整数一共有%d位\n",k);&&&&&&&&for(i=k-<SPAN style="COLOR: #; i&=<SPAN style="COLOR: #; --i)&&&&{&&&&&&&&printf("第%d位的数字是%d\n",i+<SPAN style="COLOR: #,a[i]);&&&&}&&&&&&&&printf("这个数的逆序输出是:");&&&&for(i=<SPAN style="COLOR: #; i&k; ++i)&&&&{&&&&&&&&printf("%d",a[i]);&&&&}&&&&printf("\n");&&&&&&&&return <SPAN style="COLOR: #;}/*在VC++6.0中的输出结果为:————————————输入一个正整数(1~99999):0输入超出范围,请重新输入一个正整数(1~9输入超出范围,请重新输入一个正整数(1~9这个整数一共有5位第5位的数字是1第4位的数字是2第3位的数字是3第2位的数字是4第1位的数字是5这个数的逆序输出是:54321Press any key to continue输入一个正整数(1~9这个整数一共有4位第4位的数字是1第3位的数字是2第2位的数字是3第1位的数字是4这个数的逆序输出是:4321Press any key to continue————————————*/
1if时间:日11:20:53题目:习题4.10 企业发放的奖金根据利润提成,从键盘输入当月利润I,求应发奖金总数。要求:用if语句编程序*/# include &stdio.h&int main(){&&&&double profit,bonus=<SPAN style="COLOR: #;&&&&&&&&printf("输入当月利润I:");&&&&scanf("%lf",&profit);&&&&&&&&if(profit&<SPAN style="COLOR: #00000)&&&&{&&&&&&&&bonus = <SPAN style="COLOR: #.0/<SPAN style="COLOR: #0*(profit-<SPAN style="COLOR: #00000);&&&&&&&&profit = <SPAN style="COLOR: #00000;&&&&}&&&&if(profit&=<SPAN style="COLOR: #00000 && profit&<SPAN style="COLOR: #0000)&&&&{&&&&&&&&bonus += <SPAN style="COLOR: #.5/<SPAN style="COLOR: #0*(profit-<SPAN style="COLOR: #0000);&&&&&&&&profit = <SPAN style="COLOR: #0000;&&&&}&&&&if(profit&=<SPAN style="COLOR: #0000 && profit&<SPAN style="COLOR: #0000)&&&&{&&&&&&&&bonus += <SPAN style="COLOR: #.0/<SPAN style="COLOR: #0*(profit-<SPAN style="COLOR: #0000);&&&&&&&&profit = <SPAN style="COLOR: #0000;&&&&}&&&&if(profit&=<SPAN style="COLOR: #0000 && profit&<SPAN style="COLOR: #0000)&&&&{&&&&&&&&bonus += <SPAN style="COLOR: #.0/<SPAN style="COLOR: #0*(profit-<SPAN style="COLOR: #0000);&&&&&&&&profit = <SPAN style="COLOR: #0000;&&&&}&&&&if(profit&=<SPAN style="COLOR: #0000 && profit&<SPAN style="COLOR: #0000)&&&&{&&&&&&&&bonus += <SPAN style="COLOR: #.5/<SPAN style="COLOR: #0*(profit-<SPAN style="COLOR: #0000);&&&&&&&&profit = <SPAN style="COLOR: #0000;&&&&}&&&&if(profit&=<SPAN style="COLOR: #0000 && profit&=<SPAN style="COLOR: #)&&&&{&&&&&&&&bonus += <SPAN style="COLOR: #.0/<SPAN style="COLOR: #0*&&&&}&&&&printf("可获得奖金总数为%lf\n",bonus);&&&&&&&&return <SPAN style="COLOR: #;}/*在VC++6.0中的输出结果为:————————————输入当月利润I:100000可获得奖金总数为Press any key to continue输入当月利润I:200000可获得奖金总数为Press any key to continue输入当月利润I:400000可获得奖金总数为Press any key to continue输入当月利润I:600000可获得奖金总数为Press any key to continue输入当月利润I:1000000可获得奖金总数为Press any key to continue输入当月利润I:2000000可获得奖金总数为Press any key to continue————————————*/
2switch时间:日11:20:53题目:习题4.10 企业发放的奖金根据利润提成,从键盘输入当月利润I,求应发奖金总数。要求:用switch语句编程序*/# include &stdio.h&int main(){&&&&double profit,bonus=<SPAN style="COLOR: #;&&&&&&&&printf("输入当月利润I:");&&&&scanf("%lf",&profit);&&&&&&&&switch(int(profit)/<SPAN style="COLOR: #0000)&&&&{&&&&default:&&&&&&&&bonus += <SPAN style="COLOR: #.0/<SPAN style="COLOR: #0*(profit-<SPAN style="COLOR: #00000);&&&&&&&&profit = <SPAN style="COLOR: #00000;&&&&case <SPAN style="COLOR: #:&&&&case <SPAN style="COLOR: #:&&&&case <SPAN style="COLOR: #:&&&&case <SPAN style="COLOR: #:&&&&case <SPAN style="COLOR: #:&&&&&&&&bonus += <SPAN style="COLOR: #.5/<SPAN style="COLOR: #0*(profit-<SPAN style="COLOR: #0000);&&&&&&&&profit = <SPAN style="COLOR: #0000;&&&&case <SPAN style="COLOR: #:&&&&case <SPAN style="COLOR: #:&&&&&&&&bonus += <SPAN style="COLOR: #.0/<SPAN style="COLOR: #0*(profit-<SPAN style="COLOR: #0000);&&&&&&&&profit = <SPAN style="COLOR: #0000;&&&&case <SPAN style="COLOR: #:&&&&case <SPAN style="COLOR: #:&&&&&&&&bonus += <SPAN style="COLOR: #.0/<SPAN style="COLOR: #0*(profit-<SPAN style="COLOR: #0000);&&&&&&&&profit = <SPAN style="COLOR: #0000;&&&&case <SPAN style="COLOR: #:&&&&&
浏览51018次
(10189)(6128)(5972)(3936)(3259)(1490)(1417)(1009)(978)(977)给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字
:给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。
&01 package com.&
02 import java.util.*;&
04 public class Test24 {&
05&&&& public static void main(String[] args){&
06&&&&&&&& Scanner sc = new Scanner(System.in);&
07&&&&&&&& System.out.println(&请输入一个不大于5位的正整数:&);&
08&&&&&&&& String s = sc.nextLine();&
09&&&&&&&& //将s转换为字符数组 赋值给ss&
10&&&&&&&& char [] ss = s.toCharArray();&
11&&&&&&&& int count = 0;&
12&&&&&&&& for(int i =ss.i&0;i--){&
13&&&&&&&&&&&& System.out.print(ss[i-1]);&
14&&&&&&&&&&&& count++;&
15&&&&&&&& }&
16&&&&&&&& System.out.println();&
17&&&&&&&& System.out.println(&这个数的位数为:&+count);&}

我要回帖

更多关于 适合编程的输入法 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信