C语言 设计算法输入一个四位正整数,将它们倒排,例如输入1234,输出4321。

设计算法输入一个四位正整数,将它们倒排,例如输入1234,输出4321。 (提示:分别应用/ 求整数部分,%求余数部分。例如7/5=1,7%5=2)。

第1个回答  2011-04-12
#include ""
char str_a[5];
char i=0;
char * str_pt;
char *str_pt2;
main()
{
printf("请输入四位: /n");
gets(" %s ",str_a);
str_pt=str_a;
for(i=0;i<4;i++)
{
str_pt2+i=str_pt+5-i;
}
puts("%s ",str_pt2);
}
第2个回答  2011-04-12
#include <stdio.h>
#include <stdlib.h>

int main()
{
char a[4]="0000";
int b=0;
scanf("%d",&b);
itoa(b,a,10);
printf("开始:a=%s\n",a);
int i,temp=0;
for(i=0;i<2;i++)
{
temp=a[i];
a[i]=a[3-i];
a[3-i]=temp;
}
printf("改后:a=%s\n",a);
printf("b=%d\n",b);
return 0;
}
第3个回答  2011-04-12
#include<stdio.h>
main()
{
int i,num,temp=0;
printf("Please input a numbers(0<x<9999)");
scanf("%d",&num);
while(num>=10)
{
temp=temp*10+num%10;
num/=10;
}
temp=temp*10+num;
printf("The number is %d",temp);
}
第4个回答  推荐于2017-11-24
// z2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<math.h>
using namespace std;
void Reverse(int &m)//m为4位整数
{
m=1000*(m%10)+100*(m%100/10)+10*(m%1000/100)+m/1000;
}

int main()
{
int m;
cout<<"请输入一个4位整数:"; //m为4位整数
cin>>m;
Reverse(m);
cout<<"倒排后为:"<<m<<endl;
system("pause");
return 0;
}
求最佳 3Q本回答被提问者采纳
第5个回答  2011-04-12
//---------------------------------------------------------------------------

#include <stdio.h>

int main(void)
{
char c;
if ((c=getchar())!='\n') main();
putchar(c);
return 0;
}
//---------------------------------------------------------------------------

相关了解……

你可能感兴趣的内容

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