编程题 从键盘上输入1个4位的整数a,分解出每一位数字,按逆序的数字组合出新的整数b。

如题所述

main()

{int a,b=0,t;

scanf("%d",&a);

t=a;

while(t>0)

{b=b*10+t%10;

t/=10;}

printf("a=%d\n",a);

printf("b=%d\n",b);}

例如:

#include<iostream>

using namespace std;

int main()

{

int n;

printf("please input n (xxxx):");

scanf("%d",&n);

while(n!=0)

{

cout<<n%10<<endl;

n=n/10;

扩展资料:

整数中,能够被2整除的数,叫做偶数。不能被2整除的数则叫做奇数。即当n是整数时,偶数可表示为2n(n 为整数);奇数则可表示为2n+1(或2n-1)。

偶数包括正偶数(亦称双数)、负偶数和0。所有整数不是奇数,就是偶数。

十进制里,我们可用看个位数的方式判断该数是奇数还是偶数:个位为1,3,5,7,9的数为奇数;个位为0,2,4,6,8的数为偶数。

参考资料来源:百度百科-整数

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-06-02
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    cout<<s;
    return 0;
}

第2个回答  2019-03-17
#include<iostream> using namespace std; void main() { int num; cout<<"input the data:"<<endl; cin>>num; if(num<1000||num>9999) do{ cout<<"input wrong,try again!"<<endl; cin>>num; }while(num<1000||num>9999); int temp=num,a[4],i=0; cout<<"the reverse sorted is:"<<endl; for(i=0;i<4;i++) { a[i]=temp%10; temp/=10; cout<<a[i]; } cout<<endl; for(i=0;i<4;i++) for(int j=i+1;j<4;j++) { if(a[i]>a[j]) temp=a[i]; a[i]=a[j]; a[j]=temp; } cout<<"the maximum number which build by the "<<num<<" is:"<<endl; for(i=0;i<4;i++) cout<<a[3-i]; cout<<endl; cout<<"the minimum number which build by the "<<num<<" is:"<<endl; for(i=0;i<4;i++) cout<<a[i]; cout<<endl; }
第3个回答  2019-05-16
Scanner sc=new Scanner(System.in);
String str=sc.next();
String []arr=str.split("");
for(int i=3;i>=0;i--){
System.out.print(arr[i]);
}
没有加上是不是整型的判断
第4个回答  2019-03-16
main()
{int a,b=0,t;
scanf("%d",&a);
t=a;
while(t>0)
{b=b*10+t%10;
t/=10;}
printf("a=%d\n",a);
printf("b=%d\n",b);}本回答被网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网