int main(int argc, char *argv[])
{
int i,sum=0;
char ch[5]={"\0"};
for(i=1;i<=100;i++)
{
sprintf(ch,"%03d",i);
if(ch[2]=='3')
{
sum=sum+i;
}
else
{
continue;
}
}
printf("\nsum= %d",sum);
return 0;
}
///////////////////ç¨while/////////////////////
int main(int argc, char *argv[])
{
int i=0,sum=0;
char ch[5]={"\0"};
while(i<=100)
{
i++;
sprintf(ch,"%03d",i);
if(ch[2]=='3')
{
sum=sum+i;
}
else
{
continue;
}
}
printf("\nsum= %d",sum);
return 0;
}
温馨提示:内容为网友见解,仅供参考