同学的答案
#include "stdafx.h"
#include<iostream>
using namespace std;
int PP(int n)
{
int m=0;
for(;n>0;)//为什么两边要有;
{
int t=n%10;
n/=10;
m++;
}
return m;
}
int _tmain(int argc, _TCHAR* argv[])
{
int n;
cin>>n;
int a=PP(n);
int s=0,i=a;
for(;n>0;)
{
int t=n%10;
n/=10;
s+=t*pow(10,(i-1));
i--;
}
cout<<s<<endl;
system("PAUSE");
return 0;
}
............for(;n>0;)//为什么两边要有;
for计数循环需要三个部分,一般可以这样理解:
for(循环初值;循环条件;循环步长){for(; n>0;)这种写法也就省略了初值和步长,因为联系上下文也可以找到初值和步长。
其实可以写成规范的当型循环while:
所以代码就是:
#include <bits/stdc++.h>