Advertisement
Josif_tepe

Untitled

Mar 4th, 2024
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9.     int a,b;
  10.     int suma =0;
  11.     cin>>a>>b;
  12.     if(b == 1) {
  13.         cout << a / 100 << endl;
  14.     }
  15.     else if(b == 2) {
  16.         cout << (a / 10) % 10 << endl;
  17.     }
  18.     else if(b == 3) {
  19.         cout <<a % 10 << endl;
  20.     }
  21.     else {
  22.        
  23.        
  24.         for(int i =1;i<=b-3;i++){
  25.             int posledna_cifra = a%10;
  26.             int vtora_cifra = (a/10)%10;
  27.             int prva_cifra = a/100;
  28.             suma=posledna_cifra+vtora_cifra+prva_cifra;
  29.             int c=suma%10;
  30.             a*=10;
  31.             a+=c;
  32.             a%=1000;
  33.            
  34.            
  35.         }
  36.         cout<<a%10<<endl;
  37.     }
  38.     return 0;
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement