我需要得到包含数字1的数字位数.我知道在java中我可以将输入作为a String
和use使用charAt
,但我知道C中没有隐式的String函数.我怎样才能实现这一点?
分裂和模数是你的朋友.
#include "stdio.h"
int main(){
int digits[] = {0,0,0,0,0,0,0,0,0,0};
int i = 11031;
while(i > 0){
digits[i % 10]++;
i = i / 10;
}
printf("There are %d ones.\n", digits[1]);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10845 次 |
最近记录: |