int main(int argc, const char * argv[]) {
@autoreleasepool {
int num;
int temp;
printf("请输入一个整数:");
scanf("%d", &num); // 接收用户输入的整数,并赋值给变量data
printf("%d从最低位到最高位分别为:", num);
while(num>0) // 当data=0或小于0时,退出循环,此时所以位数都已取出
{
temp = num % 10; // 取出data的最低位
// 把数字转为对象
NSNumber *arr =[NSNumber numberWithInt:temp];
//创建空的字典
NSMutableDictionary *dict= [NSMutableDictionary dictionary];
if (temp==1) {
[dict setObject:@"One" forKey:arr];
}
else if(temp==2){
[dict setObject:@"Two" forKey:arr];
}
else if(temp==3){
[dict setObject:@"Three" forKey:arr];
}
else if(temp==4){
[dict setObject:@"Four" forKey:arr];
}
else if(temp==5){
[dict setObject:@"Five" forKey:arr];
}
else if(temp==6){
[dict setObject:@"Six" forKey:arr];
}
else if(temp==7){
[dict setObject:@"Seven" forKey:arr];
}
else if(temp==8){
[dict setObject:@"Eight" forKey:arr];
}
else if(temp==9){
[dict setObject:@"Nine" forKey:arr];
}
else if(temp==0){
[dict setObject:@"Zero" forKey:arr];
}
[dict enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
NSLog(@"%@",obj);
}];
num /= 10; // 输出最低位
// 将去掉data的最低位,次低位变为最低位
}
}
return 0;
}
|
|