+ 1
Why the answer is always -1
#include <iostream> using namespace std; int digit(long,int); int main() { long n; int k; cin>>n>>k; cout<<digit(n,k)<<endl; return 0; } int digit(long n , int k) { int a,b,c,e; for (b=0;a>0;b++) {a=n/10;} int NUM[b+1]; for (c=1;c<=b;c++) {NUM[c]=n%10;} if (k<=b) e=NUM[k]; else e=-1; return e; }
1 Answer