In C ++ / separation Magical% and when you

In the process of learning c ++, we generally use / and% to break down each digit

ToSei (/)

Such as 1234/10 is equal to 123.4, which corresponds to the exploded top three out

Modulo (%)

Decomposition method such as 12345

Bit: 12345% 10 = 5

Ten: 12345% 100/10 = 4

One hundred: 12345% 1000/100 = 3

Thousands: 12345% 10000/1000 = 2

Ten thousand: 12345/10000 = 1

#include <stdio.h>
using namespace std;
int main()
{
  int x;//这是我们输入的数字
  scanf("%d",&x);//输入语句
  int a,b,c,d,e;
  a=x/10000;    //分解出万位

    b=x%10000/1000;      //分解出千位

    c=x%1000/100;             //分解出百位

    d=x%100/10;      //分解出十位

    e=x%10;         //分解出个位
  printf("%d %d %d %d %d ",a,b,c,d,e);
  return 0;
}

Guess you like

Origin www.cnblogs.com/LJA001162/p/11031789.html