关于C++的问题求高手解答,跪谢!

来源:百度知道 编辑:UC知道 时间:2024/06/07 10:37:53
1 Convert the following code fragment so that it uses a while loop instead of a for loop. That is, your code should not use any for statements. Make sure your code still produces the same output. You may assume that k and i are integer variables.
k = 100;
for ( i = 0, j = k; i < j; i++, j-=2)
printf("%d, %d", i, j);

2 Complete the C function printRange that accepts 2 integer values x and y, and prints all the integers from x to y. For example, if x is 12 and y is 17, the function should print:

12 13 14 15 16 17

The function should print nothing if x is greater than y. The function does not have any return values.

void printRange(int x, int y)

1)
int i=0,j=100,k=100;
while(i<j){
printf("%d, %d",i,j);
++i,j-=2;
}

2)
void printRange(int x,int y)
{
for(;x<=y;++x)
printf("%d ",x);
}

k = 100;
i = 0;
j = k;
while(i < j )
{printf("%d, %d", i, j);
i++;
j-=2;}

void printRange(int x, int y)
{
for(int i=x;i<=y;printf("%d ",i))
;
}
下次能不能不要用英文好不

1, int k,i,j;
k=100;
j=k;
while(i<j)
{
cout<<i<<' '<<j<<endl;
i++;
j=j-2;
}

2, int x;
int y;
cin>>x>>y;
if(x>y)
cout<<"不对,x应小于y."<<endl;
else
{
while(x<=y)
{
cout<<x<<' ';
x++;
}
}