Why the answer is always -1 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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; }

27th Oct 2018, 12:02 PM
CHN k
0 Answers