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.
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
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);
}
does anyone know how to do it in python rather than C pleasee, if you know @Taufique it would be really helpful please
do you know python language?
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
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 ..
I can only understand you logic bro..
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
do in python what i am saying...
in python declare variables as integer their name is n,p,b... hurry up..
so write def
def (a,b) --> c ?
like how do i know they are integers it just confuses me on how to set it up
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..
like he also gave this for help def nth_digit(): #You need to change the parameters. pass
lol i would honestly really apppreciate it thanks a lot
hamza bhai ....first of all, write all the codes which has you tried for this program i will check it..
@asnaseer have you knowledge in python ,pls come here..
hmm i actually am trying to write it but it is not making sense in my head at all
@Preetha pls help in python language....
where do you read python..and in which class do you read...
i need it for introduction computer programmingg course
in which class
you need to be able to pick out a digit from the first number passed in. can formulate some pseudo code to do this?
csc108 introduction to computer programming
forget python. try and do this mathematically first.
@asnaseer i have do it in c ..and it is running and give correct output but how can i do this in python...
omg its so confusing both mathematically and in python
Taufique - the aim of this site is to teach - not just give entire answers out.
hamza - think about how to pick out a certain digit using maths
so in the number 1234, what can you do to isolate the digit 4?
yes I know it sorry
hamza-- try it your self only i can give you direction..
alright i am trying
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...
Join our real-time social learning platform and learn together with your friends!