题解 | #添加逗号#
添加逗号
https://www.nowcoder.com/practice/f51c317e745649c0900996fd3f683aed
#include <stdio.h> //插入逗号 int main() { int n = 0; int k = 0; char arr[14] = { 0 }; scanf("%d", &n); while (n) { if (k != 0 && (k + 1) % 4 == 0)//k从零开始,an=4n-1 { arr[k++] = ','; } else { arr[k] = n % 10+'0'; k++; n = n / 10; } } for (k--; k >= 0; k--)//arr[0]也要打印 { printf("%c", arr[k]); } return 0; }