回覆列表
-
1 # 一時有無
-
2 # 扶尾貓南巷味少
#include<stdio.h>
unsignedshortbits(intn){
inti=0;
if(n<0)n=-n;
while(n>0){
i++;
n/=10;
}
returni;
}
intmain(){
inti,a[4]={65535,-96854,33025,180};
for(i=0;i<4;i++)printf("%d是%d位數。\n",a[i],bits(a[i]));
printf("\n");
return0;
}
-
3 # 使用者6767156913043
#include
#include
int main()
{
int n,m,i=1,x;
printf("enter n:");
scanf("%d",&n);
m=n;
x=n;
if(n>99999 || n
printf("請輸入一個不多於5位數的正整數\n");
while(n>=10)
{
i++;
n=n/10;
}
printf("這是一個%d位數\n",i);
int a,b,c;
printf("按順序分別輸出:");
a=pow(10,(i-1));
b=a*10;
while(a>=1)
{
c=(x%b-x%a)/a;
printf(" %d ",c);
a=a/10;
b=b/10;
}
printf("\n");
printf("按逆序輸出:");
while(m!=0)
{
printf("%d",m%10);
m/=10;
}
return 0;
}
#include<stdio.h>#include<math.h>int main(){int n,m,i=1,x;printf("enter n:");scanf("%d",&n);m=n;x=n;if(n>99999 || n<=0)printf("請輸入一個不多於5位數的正整數\n");while(n>=10){i++;n=n/10;}printf("這是一個%d位數\n",i);int a,b,c;printf("按順序分別輸出:");a=pow(10,(i-1));b=a*10;while(a>=1){c=(x%b-x%a)/a;printf(" %d ",c);a=a/10;b=b/10;}printf("\n");printf("按逆序輸出:");while(m!=0){printf("%d",m%10);m/=10;}return 0; }