这行修改成
a+=(temp%10==1)? 1 : 0;
#include"head.h"
#include
using namespace std;
int main()
{
int a=0,i,N,temp;
scanf("%d",&N);
for(i=1;i<=N;++i)
{
temp=i;
while(temp!=0)
{
a+=(temp%10==1?1:0);//条件表达式含有问号。
temp/=10;
}
}
return 0;
}
a+=((temp%10)==1);
问号跑哪里去了