alt_438's blog

By alt_438, history, 3 years ago, In English

Given a positive integer N and a digit D. The task is to find out the place value of a digit D in the given number N. If multiple occurrences of digit occur then find the maximum place value. please suggest how to solve this problem.

  • Vote: I like it
  • -8
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Chup randi

»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it
int main(){
  int n,d;
  scanf("%d%d",&n,&d);
  
  int rem,temp,answer = 0;
  temp = 1;
  while(1){
    rem = n%10;
    n = n/10;
   
    if(rem == d){
        answer = temp*rem;
        break;
    }
    temp *= 10;
  }
  printf("%d",answer);
}

I think the code is self understandable.