例题6
#include<iostream>
using namespace std;
#include<cmath>
int main()
{
double e = 1.0, u = 1.0;
double i = 1.0;
while (u >= 1.0e-7)
{
e = e + u;
i++;
u = u / i;
}
cout <<"e=" <<e<< endl;
return 0;
}
例题7
#include<iostream>
using namespace std;
int main()
{
int i, j, k;
cout << "水仙花数有:";
for (int n = 100; n < 1000; n++)
{
i = n % 10;
j = (n / 10) % 10;
k = n / 100;
if (n == i * i*i + j * j*j + k * k*k)
{
cout << n << " ";
}
}
return 0;
}