循环06~~~10

循环-06

#include
#include
int main()
{
using namespace std;
string s;
int num = 0;
cout << "Enter your word :\n";
while (cin>>s)
{
num++;
if (cin.get() == '\n')
break;
}
cout << "We have " <return 0;
}


循环-07

#include
using namespace std;
int main()
{
int N, U, D;
cout << "Enter N/U/D in turn :";
cin >> N >> U >> D;
int time = 0; int height = 0;
while (height < N)
{
time++;
if (time % 2)
height = (time / 2 + 1)*U - (time / 2)*D;
else
height = (time / 2)*(U - D);
}
cout << "Time = " << time << endl;
return 0;
}


循环-08

#include
#include
using namespace std;
double f(double a3, double a2, double a1, double a0, double x);
int main()
{
double a3, a2, a1, a0;
cout << "Enter a3,a2,a1,a0 :";
cin >> a3 >> a2 >> a1 >> a0;

double a, b;
cout << "Enter a,b :";
cin >> a >> b;
cout << fixed;
cout.precision(2);
while (a0.01))
{
if (f(a3, a2, a1, a0, a)*f(a3, a2, a1, a0,b) > 0)
{
cout << "Equation has no root .\n";
break;
}
else
{
if (f(a3, a2, a1, a0, (a + b) / 2) == 0)
cout << "Root = " << (a + b) / 2;
else
{
if (f(a3, a2, a1, a0, a)*f(a3, a2, a1, a0, (a + b) / 2) > 0)
a = (a + b) / 2;
else
b = (a + b) / 2;
}
}
}
cout << "Root = " << (a + b) / 2;
return 0;
}
double f(double a3, double a2, double a1, double a0, double x)
{
return a3*pow(x, 3) + a2*pow(x, 2) + a1*x + a0;
}


循环-09

#include
int main()
{
using namespace std;
int y=0;int f=0;
int n;
cout << "Enter value n less than 100 :"; 
cin >> n;
while (n<100&&f<100)
{
f++;
if ((98*f-n)%199==0)
{
y = (98 * f - n) / 199;
cout << y << '.' << f << endl;
break;
}
}
if (y == 0)
cout << "No solution .\n";
return 0;
}


循环-10

#include
using namespace std;
double change(int n);
int main()
{
int N; 
cout << "Enter vlaue N :"; cin >> N;
double sum = change(N);
cout << fixed;
cout.precision(2);
cout << sum;
return 0;
}
double change(int n)
{
double a = 2.0; double b = 1.0; double temp;
double tot = 0;
while (n--)
{
tot += a / b;
temp = b; b = a; a = a + temp;
}
return tot;
}

你可能感兴趣的:(循环06~~~10)