1) y=y+ static_coast<double> i / (i+1)
2) y=y+ (double) i/(i+1)
Break
i=1;
while(1)
{
if(i>10) break;
cout<<i=<<i<<_;
i++;
}
cout<<endl;
:1_2_3_4_5_6_7_8_9_10
Continue
for (i=1;i<10;i++)
{
if (i %2) continue;
cout<<i<<_;
}
:2_4_6_8
Goto
goto
100 .
i=1;
loop1:
cout<<i<<_;
i++;
if (i<=100) goto loop1;
:1_2_3_4_5_6_7_... _100
switch ()
switch () { case 1: [ ]
case 2: [ ]
.
case n: [ ]
default: [ ]
}
1
# include <iostream.h>
void main()
{
int a,b,res;
char op;
cout << enter 1 operand:;
cin>>a;
cout << enter sign of operation:;
cin>>op;
cout << enter 2 operand:;
cin>>b;
bool f=true;
switch (op) {
case +: res=a+b; break;
case -: res=a-b; break;
case *: res=a*b; break;
case /: res=(double) a/b; break;
default: cout<<unknown operator <<endl;
f=false;
}
if (f) cout<<result:<<res<<endl;
}
2
# include <iostream.h>
# include <stdlib.h>
# include <time.h>
void main()
{
bool t;
int x, y, n, i;
srand (time(0));
x=rand()%10+1;
cout<< the computer define number in the range 1-10<<endl;
t=false;
cout<< Guess the number!!!<<endl;
cout<< You must guess the number the computer<<endl;
cout<< enter n=;
cin>>n; //
i=1;
while (i<=n &&!t)
{
cout<<enter number;
cin>>y; //
if (y==x) t=true;
i++;
}
if (t)
{
cout<< You win!<<endl;
cout<< The number of attempts i = <<i<<endl;
cout<<Computer defined number:<<x<<endl;
}
else {
cout<<Sorry! The computer number =<<x<<endl;
}
}
3
true, x
T=
false, x
i=2..sqrt(x)- .
# include <iostream.h>
# include <math.h>
void main()
{
int i,x;
bool t;
cout<<enter x=;
cin>>x;
if (x<=1) t=false;
|
|
else if (x==2) t=true;
else
{
t=true;
for (i=2; i<=sqrt(x) && t; i++)
{
if (x% i==0) t=false;
}
}
if (t) cout<< x<< -prime<< endl;
else cout<< x<< - not prime<< endl;
}
4.
.
# include <iostream.h>
void main()
{
char ch;
int i;
for (ch=a;ch<=z;ch++)
cout<<ch<< ; // ( )
cout<<endl;
for (i=a;i<a+26; i++)
cout<<i<< ; //
cout<<endl;
}
5
1 .
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
void main()
{
int i, j, k, m;
int l=time (0);
int p=1;// 1
while (time (0)-l < 1)
{
cout<<time(0)<<':'<<'_';
p++;
// system("pause");
}
cout<<endl<<"p= "<<p<<endl;
// 1
cout<<endl;
cout<<"hours: minutes: second"<<endl;
for(m=0;m<=24;m++)
for(i=0; i<=59; i++)
for(j=0; j<=59;j++)
for (k=1;k<=100000;k++)//
{
cout.fill('0'); cout.width(2);
cout<<m<<':';
cout.fill('0'); cout.width (2);
cout<<i<<':';
cout.fill('0'); cout.width (2);
cout<<j<<'\r';
}
cout<<endl;
}
6
0, 1, 2,.n-1
-
++:
[]
:
int a[100] const int N=100;
int a[N];
: [].
;
▄1 ▄2 ▄ 3▄ 4
a- -, .
1