taeyounkim LOG
function that returns the k(th) digit(from the right) in n(a positive integer) 본문
Career&Study/Coding Practice
function that returns the k(th) digit(from the right) in n(a positive integer)
taeyounkim 2021. 6. 30. 12:43728x90
#include <stdio.h>
int digit(int n, int k)
{
while(k>1){
n/=10;
k--;
}
return n%10;
}
int main(){
int n, k;
printf("Enter n, k: ");
scanf("%d %d", &n, &k);
printf("%d", digit(n,k));
return 0;
}
728x90
'Career&Study > Coding Practice' 카테고리의 다른 글
Guessing a Number game codes (0) | 2021.07.05 |
---|---|
Game of Craps code, 그리고 stackoverflow.com (0) | 2021.07.02 |
function that returns the day of year (0) | 2021.06.30 |
New Coding Fact_Converting a letter to upper case (0) | 2021.06.13 |
Code that prints a one-month calendar (0) | 2021.06.12 |