Advertisement
rotti321

Transf int -> sir char

Oct 20th, 2021
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. ///Transf int -> sir char
  2.  
  3. #include <iostream>
  4. #include <cstring>
  5. using namespace std;
  6.  
  7.  
  8. int main() {
  9.     char a[256] ;
  10.     int nr,x,p=1,k=1,c;
  11.     cin>>nr;
  12.     x=nr;
  13.     while(nr>9){
  14.         nr=nr/10;//elimin ultima cifra din numar
  15.         p=p*10;
  16.         k++;//creste numarul de cifre
  17.     }
  18.    
  19.     for(int i=0;i<k;i++){
  20.         c=x/p%10;
  21.         p=p/10;
  22.         a[i]=c+'0';
  23.     }
  24.     cout<<a;
  25.    // cin.getline(a,256);
  26.    
  27.    
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement