要点:1、数字存入数组。数p74 同类型题 B1002 写出这个数
#include<iostream> using namespace std; int main() { int a,b; int sum; cin>>a>>b; sum=a+b; int num[10]; //判断是否为正数 先输出数的正负号性(负号) if(sum<0){ cout<<"-"; sum=-sum; } int len =0; //要考虑到0的特殊 do{ num[len]=sum%10; sum/=10; ++len; }while(sum); for(int k=len-1;k>=0;k--) { cout<<num[k]; if(k>0&&k%3==0)cout<<","; } //k,剩下的长度 return 0; }
原文:https://www.cnblogs.com/leamant/p/13293126.html