Thanks!
(初学)书上一道题说把一个输入的数字正反2种输出 列如:
1432
2341;
我只能想到求出这个数字的个位,十位,百位。。。然后排列.
帮我看下~谢谢!
#include <stdio.h>main()
main()
{
int s,j,gw,bw,sw,qw;
char *p;scanf("%d",&s);
printf("%d",s);
*p=sswitch(j=strlen(s))
{
case 2:gw=s%10;sw=s/10;
printf("%d%d",sw,gw);break;
case 3:gw=s%10;sw=s/10;sw=sw%10;bw=s/100;
printf("%d%d%d",bw,sw,gw);break;
case 4:gw=s%10;sw=s%100;sw=sw/10;bw=s/10;bw=bw%100,bw=bw/10;qw=s/1000;
printf("%d%d%d%d",qw,bw,sw,gw);break;
default:gw=s;
printf("%d",gw); break;
}
错啦,不是这样子,
#include <string.h>
#include <stdio.h >
#include <conio.h >
#include <alloc.h>
void main ()
{
int i , n ;
char * p = ( char * ) malloc(sizeof(char));
scanf("%s" , p) ;
printf( " %s \n " , p ) ;
n = strlen (p) ;
for ( i = n - 1 ; i >= 0 ; i -- )
printf ( "%c" , p[i] ) ;
getch () ;
free(p) ;
}
第 9 楼 错啦,不是这样子,
#include <string.h>
#include <stdio.h >
#include <conio.h >
#include <alloc.h>
void main ()
{
int i , n ;
char * p = ( char * ) malloc(sizeof(char));
scanf("%s" , p) ;
printf( " %s \n " , p ) ;
n = strlen (p) ;
for ( i = n - 1 ; i >= 0 ; i -- )
printf ( "%c" , p[i] ) ;
getch () ;
free(p) ;
}
这个才是正确的