Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

could some one help me out with this code please it says the function name is nth_digit: (int, int) -> int and the description is The first parameter is an arbitrary integer that you can think of as being base 10. The second parameter is an integer that specifies a digit in the first parameter. This function returns that digit. Digits are counted from right to left, so that 0 represents the 0s digit, 1 represents the 10s digit, 2 represents the 100s digit and so on. So nth_digit(123,0) should return 3, nth_digit(123,1) should return 2, and nth_digit(123,2) should return 1.

OpenStudy (anonymous):

You can assume the first number is positive, and the second number refers to a digit that is explicitly written. So you will not need to handle something like nth_digit(123,4). i do not know how to do this problem please help me outt

OpenStudy (anonymous):

In c language try it...... #include<stdio.h> #include<conio.h> int nth_digit(long int,int); void main() { long int n; int p,b; printf("Enter any number:"); scanf("%ld",&n); printf("Enter the position of number do you want to know"); scanf("%d",&p); b=nth_digit(n,p); printf("the number at this position is %d",b); getch(); } int nth_digit(long int x, int y) { int a[30],i=0,k; while(x>9) { a[i]=x%10; x=x/10; i++; } a[i]=x; k=a[y]; return(k);

OpenStudy (anonymous):

}

OpenStudy (anonymous):

does anyone know how to do it in python rather than C pleasee, if you know @Taufique it would be really helpful please

OpenStudy (anonymous):

do you know python language?

OpenStudy (anonymous):

yeah a little bit i just started with this course and it is so hard for me to keep up and it just doesnt make sense to me

OpenStudy (anonymous):

In any language only syntax is different but logic is same ..I have no knowledge what is the syntax of variable declaration, for print, and scanf in python ..

OpenStudy (anonymous):

I can only understand you logic bro..

OpenStudy (anonymous):

oo but i dont understand C at all lol like even for the other question i didnt know what was going on like i got plenty of answers but dont know i have to define something and make sure i write its docstrings and have to run it and make sure it works

OpenStudy (anonymous):

do in python what i am saying...

OpenStudy (anonymous):

in python declare variables as integer their name is n,p,b... hurry up..

OpenStudy (anonymous):

so write def

OpenStudy (anonymous):

def (a,b) --> c ?

OpenStudy (anonymous):

like how do i know they are integers it just confuses me on how to set it up

OpenStudy (anonymous):

wait 10 minutes i am giving you source code in python for this program.today this is my first attempt in python language bro.this is so interesting..

OpenStudy (anonymous):

like he also gave this for help def nth_digit(): #You need to change the parameters. pass

OpenStudy (anonymous):

lol i would honestly really apppreciate it thanks a lot

OpenStudy (anonymous):

hamza bhai ....first of all, write all the codes which has you tried for this program i will check it..

OpenStudy (anonymous):

@asnaseer have you knowledge in python ,pls come here..

OpenStudy (anonymous):

hmm i actually am trying to write it but it is not making sense in my head at all

OpenStudy (anonymous):

@Preetha pls help in python language....

OpenStudy (anonymous):

where do you read python..and in which class do you read...

OpenStudy (anonymous):

i need it for introduction computer programmingg course

OpenStudy (anonymous):

in which class

OpenStudy (asnaseer):

you need to be able to pick out a digit from the first number passed in. can formulate some pseudo code to do this?

OpenStudy (anonymous):

csc108 introduction to computer programming

OpenStudy (asnaseer):

forget python. try and do this mathematically first.

OpenStudy (anonymous):

@asnaseer i have do it in c ..and it is running and give correct output but how can i do this in python...

OpenStudy (anonymous):

omg its so confusing both mathematically and in python

OpenStudy (asnaseer):

Taufique - the aim of this site is to teach - not just give entire answers out.

OpenStudy (asnaseer):

hamza - think about how to pick out a certain digit using maths

OpenStudy (asnaseer):

so in the number 1234, what can you do to isolate the digit 4?

OpenStudy (anonymous):

yes I know it sorry

OpenStudy (anonymous):

hamza-- try it your self only i can give you direction..

OpenStudy (anonymous):

alright i am trying

OpenStudy (anonymous):

step1:take a number and position of digit which you want to know from the keyboard .... step2:declare a function to do this task..... step3:logic...it is very important step in any language.. in this step declare an array .. for example if anyone enter 12345 number then 12345%10=5 and 12345/10=1234 1234%10=4 and 1234/10=123 123%10=3 and 123/10=12 12%10=2 and 12/10=1 if number<9 stop this process and insert all the remainder in the array..like |dw:1338760424079:dw| now if you have entered 2 then output will be 3 from the array...now implements this in python...

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!