0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

整数8951を引き算を使って文字列8951に変換して遊ぶ。

Last updated at Posted at 2025-09-17

いろいろ注意

  • arduino unoでの予定は、未定
  • 乗除算器なしのCPU

目的

主にZ80やPIC等で10進変換

プログラム

オンラインコンパイラ paiza



#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    int N1000 = 0;
    int N100 = 0;
    int N10 = 0;
    int A = 8951;
    
    //1000
    while(A > 999){

        A = A - 1000;
        N1000 = N1000 + 1;
        
    }  //while
    
    //100
    while(A > 99){

        A = A - 100;
        N100 = N100 + 1;
        
    }  //while
    
    //10
    while(A > 9){

        A = A - 10;
        N10 = N10 + 1;
        
    }  //while
    
    //printf("N1000=%d,N100=%d,N10=%d,A=%d\n",N1000,N100,N10,A);
    
    char str[] = "0000";
    str[0] = '0' + N1000;
    str[1] = '0' + N100;
    str[2] = '0' + N10;
    str[3] = '0' + A;
    str[4] = 0;
    printf(str);
    
}  //main




8951

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?