看我的吧用数组实现的还是比较简单的俄
include<iostream>
using namespace std;
int main(){
int i=0;
unsigned int name;//输入数值
int key;//要输出的数字的位数
int count[5]={0};
cout<<"input what you want"<<endl;
cin>>name;
cin>>key;
while(name>10){
count[i]=name%10;
name=name/10;
i++;}
count[i]=name;
if(key>i)cout<<"0";
else cout<<count[key-1];
cout<<endl;
}
include<iostream>
using namespace std;
int main(){
int i=0;
unsigned int name;//输入数值
int key;//要输出的数字的位数
int count[5]={0};
cout<<"input what you want"<<endl;
cin>>name;
cin>>key;
while(name>10){
count[i]=name%10;
name=name/10;
i++;}
count[i]=name;
if(key>i)cout<<"0";
else cout<<count[key-1];
cout<<endl;
}
第一题
#include<stdio.h>
main()
{int num,x,i,k,z,temp;
printf("Please input an integer:");
scanf("%d",&num);
temp=num;
printf("请输入第N位数");
scanf("%d",&x);
for(i=1;num!=0;i++)
num/=10;
if(x>i) printf("0");
else {for(k=1;k<x;k++)
temp/=10;
z=temp%10;
printf("%d",z);
}
好象不对! for(i=1;num!=0;i++)中i 是一只寻环只到 num !=0 但num的下一个数可能是随机的可能不为0 i还要寻换