题目: 对一个8进制数进行移位,先输入该8进制数,然后输入移位的位数,且正数表示右移,负数表示左移。
/*EX6-2*/
#include
unsigned moveright(unsigned,int);
unsigned moveleft(unsigned,int);
main()
{
unsigned a;
int n;
printf(“Input an octal number:”);
scanf(“%0”, &a);
printf(“\n Input the bit number of rotation:”);
scanf(“%d”, &n);
if(n>0)
{
moveright(a,n);
printf(“\n Rotate right: %0 \n”,moveright(a,n));
}
else
{
n=-n;
moveleft(a,n);
printf(“\n Rotate left: %0\n”,moveleft(a,n));
}
return 0;
}
unsigned moveright(unsigned a,int n)
{
unsigned t;
t=(a>>n)|(a>(16-n)|(a<<n));
return (t);
}
错误:运行时Input an octal number那里没有让我输入东西,而是直接让我输入:Input the bit number of rotation:也就是说在点击运行后,出现了:
Input an octal number:
Input the bit number of rotation:
我这是从学校教材里扒下来的,教材是这么写的.
这么说的话,这个代码里所有的%0都要改成%d?我看到有三处都是%d
|