1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

自分専用の整数を文字列に変換する。ただし、順番が逆

Posted at
  • UNO での 予定は、未定
  • UNO に itoaが無いので?
  • 順番が逆

プログラム


#include <iostream>
using namespace std;

void myitoa(char *str,int num){
    
    int m = 0;
    if(num < 0){
        num = 0 - num;
        m = 1;
    }
    
    do{
        *str++ = num % 10 + '0';
        num /= 10;
    }while(num != 0);
    
    if(m == 1 ){
        *str++ = '-';
    }

    *str = 0;
    
}

int main(void){
    // Your code here!
    char s[32];
    myitoa(s,1234);
    printf("%s\n",s);
    myitoa(s,-1234);
    printf("%s\n",s);
}


4321
4321-

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?