VasilakiG

11ta kolokviumska prv semestar so logaritmi

Dec 1st, 2021 (edited)
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. //pravi problem koga second digit==0
  4. int main (){
  5.  
  6.     int number, copynumber, copynumber2;
  7.     int last_digit, secondtolast_digit;
  8.     int flag;
  9.     while(scanf("%d", &number)){
  10.         if(number<=10){
  11.             continue;
  12.         }
  13.         else{
  14.             int temp=number;
  15.             copynumber=0;
  16.             int coef=1;
  17.             int lastdigittemp, secondtolastdigittemp;
  18.  
  19.             lastdigittemp=temp%10;
  20.             secondtolastdigittemp=temp%100/10;
  21.  
  22.             if(lastdigittemp < secondtolastdigittemp){
  23.                 flag=2;
  24.             }
  25.             if(lastdigittemp > secondtolastdigittemp){
  26.                 flag=1;
  27.             }
  28.  
  29.             while(temp!=0){
  30.  
  31.                 last_digit=temp%10;
  32.                 secondtolast_digit=temp%100/10;
  33.  
  34.                 if(flag==3){
  35.                     copynumber+=temp*coef;
  36.                     coef=coef*100;
  37.                 }
  38.  
  39.                 if(flag==2){
  40.                     if(last_digit<5 && secondtolast_digit>=5){
  41.                         copynumber+=(secondtolast_digit*10+last_digit)*coef;
  42.                         coef=coef*100;
  43.                     }
  44.                 }
  45.                 if(flag==1){
  46.                     if(last_digit>=5 && secondtolast_digit<5){
  47.                         copynumber+=(secondtolast_digit*10+last_digit)*coef;
  48.                         coef=coef*100;
  49.                     }
  50.                 }
  51.  
  52.                 temp/=100;
  53.                 if( log10( (double)temp ) >=0 && log10( (double)temp ) <= 1  ){
  54.                     flag = 3;
  55.                 }
  56.             }
  57.  
  58.             if(copynumber==number){
  59.                 printf("%d\n", copynumber);
  60.             }
  61.         }
  62.     }
  63.  
  64.     return 0;
  65. }
Add Comment
Please, Sign In to add comment