++ . , , .
, , , . , , .
. , , , . . , , .
, . - . :
D 1: x = x * sin (x); //D1 . x= x*sin(x); - .
D 2:; // D2 . - .
, . , , , , . , . , . . ( ) .
{ int f; char st = 0; = (int) st; } // ( )
{ sin (2* x); x = x -4;} //
, , , .
: (if else) (switch). .
:
if() _1 else _2
. ( ), _1. , _2. _1 _2 , . . 4.1 -.
. 4.1.
, else _2. ( ) , . - , else , . 4.2.
|
|
. 4.2. -
, _1 _2 , . , , .
if else. , else if. :
// 1
if(x==1) // 1
if(y==1) cout<< 1 y 1; // 2
else cout<< x 1; // 3
// 2
if(x==1){ // 4
if(y==1) cout<< 1 y 1; // 5
}
else cout<< x 1; // 6
else if, . else if, . , , x, , x 1. ( ) . , . - . 4.3.
. 4.3. -
. 4.4 -
switch . :
switch (_){
case __1: _1;
case __2: _2;
case __N: _N;
default: ;
}
_1 _N , . switch case , . . , case, . , . , , switch()
case _:
, , default:. default, . default , case, .
case _: default: . break, goto, return, , , . :
|
|
// 4.1
#include "stdafx.h"
#include <iostream> //1
void main(){ //2
int ic; //3
std::cout<<"\n Input any decimal digit: "; //4
std::cin >> ic; //5
switch(ic%2){ //6
case 0: std::cout<< "\n Input an even number"; break;//7
case 1: std::cout<< "\n Input an odd number"; break;//8
default: std::cout<< "\n it is not known ic = "<<ic; //9
} //10
getchar();
} //11
, . , , break , switch, .. 11.
. :
-:
while(_ )
. 4.5. -
-:
do
while (_ );
. 4.6. -
-:
for(_; _; )
. 4.7. -
- ( ) , , , . , . , ( , ) , - .
:
;
(break; goto; return) .
, .
while . _. , . - , .. , _ . _ , , . :
// 4.2
#include "stdafx.h"
#include <iostream>
//
void main(){
std::cout<<"\n Input string = ";
char buf[100];
std::cin>>buf;
long len =0;
while (buf[len]) len++; /* (len++) */
std::cout<<"\n The number of symbol are = "<<len;
getchar();
}
, ++ . , , , .
. , N ( ):
int i =0;
long s = 0;
long N = 6;
while(i < N) s+=++i*i;// - s+=++i*i;
|
|
cout<<s;
, i < N .
? , . , (Ctrl+Break) . :
while (1); // .
_ .