converting the loop

please check my answer ???>>
Convert the following loop to a while loop without using any break statement.
#include <iostream>
using namespace std;
int main()
{
int k, sum(1);
for (k=1; k<10; k++)
{
sum *= k;
if (sum > 10*k)
break;
}
cout << "sum = " << sum << endl;
return 0;
}
my answer is
1
2
3
4
5
6
7
8
9
10
11
12
13
  #include <iostream>
using namespace std;
int main()
{
int k=1, sum(1);
while ((k<10) && (sum<10*k))
{
sum *=k;
k++;
}
cout << "sum = " << sum << endl;
return 0;
}
while ((k<10) && (sum<=10*k))


Topic archived. No new replies allowed.