直接來看代碼
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]){
int i,n;
cout << "本例測試奇數與偶數(odd and even test)\n";
n=10;
for(i=0;i<n;i++){
if((i+n)%2==0)printf("i=%d 偶數(even)\n",i);
if((i+n+1)%2==0)printf("i=%d 奇數(odd)\n",i);
}
system("PAUSE");
return EXIT_SUCCESS;
}
執行結果