想要计算从数字n到数字m之间(包含n和m)有多少个数字d出现,下列程序哪个能够实现( )。
- A. 1 int n,m,res,d; 2 cin >> n >> m>>d; 3 for(int i = n+1; i <= m; i++){ 4 int temp = i; 5 while(temp){ 6 if(temp % 10 == d) res++; 7 temp /= 10; 8 } 9 } 10 cout << res << endl; 11 return 0;
- B. 1 int n,m,res,d; 2 cin >> n >> m>>d; 3 for(int i = n; i <= m; i++){ 4 int temp = i; 5 while(temp){ 6 if(temp % 10 = d) res++; 7 temp /= 10; 8 } 9 } 10 cout << res << endl; 11 return 0;
- C. 1 int n,m,res=0,d; 2 cin >> n >> m>>d; 3 for(int i = n; i <= m; i++){ 4 int temp = i; 5 while(temp){ 6 if(temp % 10 == d) res++; 7 temp /= 10; 8 } 9 } 10 cout << res << endl; 11 return 0;
- D. 1 int n,m,res=0,d; 2 cin >> n >> m>>d; 3 for(int i = n; i <= m; i++){ 4 while(temp){ 5 if(temp % 10 == d) res++; 6 temp /= 10; 7 } 8 } 9 cout << res << endl; 10 return 0;
正确答案:C