用一个循环1-10 打印1-10 的奇数,然后打印偶数
for(int i=0; i<9; i++) { cout << (i%5)*2 + (i/5) + 1 << endl; }
if(i<=5)
{
cout<<i*2 -1;
}
else
{
cout<<(i -5)*2<<endl;
}
#include
<
iostream
>
static
int
counter
=
1
;
class
printer{
int
even_;
public
: printer() { even_
=
0
;
if
( counter
%
2
!=
0
) std::cout
<<
counter
<<
std::endl;
else
even_
=
counter; counter
++
; }
~
printer() { }
void
print_even() {
if
(even_
!=
0
) std::cout
<<
even_
<<
std::endl; }};
int
main(
int
argc,
char
**
argv){ printer print[
9
];
for
(
int
i
=
0
; i
<
9
;i
++
){ print[i].print_even(); }
return
0
;}
#include<iostream>
using namespace std;
int main(){
FILE *f[]={fopen("G:\\con1.txt","w"),fopen("G:\\con2.txt","w")};
for(int i=1;i <=10;fprintf(f[(i+1)%2],"%d\n",i++))
{
cout<<"e"<<endl;
}
system("pause");
return 0;
}