:
if ( ) 1;
else 2;
, 0 (), 1, 2, :
if(x>y) max = x;
else max = y;
1, 2 , { }, .. .
else , if .
1, 2 if, , else if.
, x, y, z:
if (x>y)
if (x>z) max=x;
else max=z;
else if(y>z) max=y;
else max=z;
: < (), <= ( ), > (), >= ( ), != ( ), = = (). .
, :
1 2
, .
. :
! ( ), && ( ), || ( ).
: (0<x)&&(x<=100)
((!x)&&(y>0)||((z==1)&&(k>0))
, , .
() ?:
:
1? 2: 3
1 ( 0), 2, 3.
, : max = a>b? a: b;
switch
():
switch () {
case const_1: ; break;
case const_N: ; break;
default: ;
}
, . case. const _1,, const _ N . default , , . break switch ( case ). break case , case break, switch.
:
swith(i) {
case 1: f=pow(x,2); break;
case 2: f=fabs(x); break;
case 3: f=sqrt(x); break;
default: printf(!); exit(1);
}
f=f+5;
|
|
x, y z.
, .
( - , ):
#include <conio.h> // #include <iostream.h>
#include <stdio.h>
#include <math.h>
void main()
{
double x, y, z, u;
puts("Input x, y, z"); // cout << "Input x, y, z" << endl;
scanf("%lf%lf%lf",&x, &y, &z); // cin >> x >> y >> z;
if (x*y > z){
u = x*sin(y);
puts(" x*y > z"); // cout << " x*y > z" << endl;
}
else {
u = y*cos(x);
puts(" x*y <= z"); // cout << " x*y <= z" << endl;
}
printf("\n\t Rezult U = %8.6lf", u); // cout << "\n\t Rezult U = " << u;
puts("\nPress any key... "); // cout <<"\nPress any key... " << endl;
getch();
}
, , , :
1 :
2 :
rez .
, . , . , , .
1. rez =
2. rez =
3. rez =
4. rez =
5. rez =
6. rez =
7. rez =
8. rez =
9. rez =
10. rez = .
11. rez =
12. rez =
13. rez =
14. rez =
15. rez =
16. rez =
3.
: while, do - while, for, . .
. . C++ .
1.
while ( )
, ( 0), = 0 () , . , .
2.
do
while ( );
, , . .
3.
for ( 1; 2; 3)
1 ; 2 ; 3 () .
|
|
1, 2, , , 3, , 2 .
break, continue .
S (x) , b c h n.
.
( - , ):
#include <stdio.h> // include <iostream.h>
#include <conio.h>
void main()
{
double a, b, x, h, r, s;
int n, zn = -1, k;
puts("Input a,b,h,n"); // cout << "Input a,b,h,n" << endl;
scanf("%lf%lf%lf%d", &a, &b, &h, &n); // cin >> a >> b >> h >> n;
for(x = a; x<=b; x+=h) {
r = s = 1;
for(k = 1; k<=n; k++) {
r=zn*r*x/k;
s+=r;
}
printf("\n x= %8.2lf sum= %8.5lf", x,s);
// cout << "\n x= " << x << " sum= " << s;
}
puts("\nPress any key... "); // cout << "\nPress any key... " << endl;
getch();
}
a =0.1, b =1.0, h =0.2 n =10, :
x, a b h, Y (x), S (x) | Y (x) S (x)| . a, b, h n . S (x) Y (x), S Y x ( ) - .
a = 0,1; b = 1,0; h = 0,1; n .
1. , .
2. .
3. .
4. .
5. .
6. .
7. , .
8. , .
9. , .
10. , .
11. , .
12. , .
13. , .
14. , .
15. , .
16. .
4.
: . .
. , (ID) (), . .
! /++ 0.
:
ID [ ];
. . .
:
int a [5];
double b [4] = {1.5, 2.5, 3.75};
[0], [1], , [4]. b, , , : b [0]=1.5, b [1]=2.5, b [2]=3.75, b [3]=0.
/++ . .
:
const Nmax=10; ;
typedef double mas1[Nmax*2]; ;
|
|
mas1 a; mas1;
int ss [10]; .
, , :
f = 2* a [3] + a [ Ss [ i ] + 1]*3;
a [ n ] = 1 + sqrt(fabs(a [ n 1]));
N ( 20), . .
- :
#include <iostream.h>
#include <conio.h>
void main()
{
int a[20], n, i, kol = 0, s = 0;
cout << "\t Input N (<=20) ";
cin >> n;
cout <<"\n\t Massiv A" << endl;
for(i = 0; i < n; i++) {
cout << "\t a[ " << i+1 << " ] = ";
cin >> a[i];
}
for(i=0; i<n;i++)
if(a[i] % 2 == 0){
kol++;
s += a[i];
}
cout << "\n Kol-vo = " << kol << "\t Summa = " << s << endl;
cout << "\n Press any key... " << endl;
getch();
}
:
( ( 20) ) :
1. , .
2. , .
3. , .
4. , .
5. , .
6. , .
7. , .
8. , .
9. , , .
10. , .
11. , .
12. , .
13. , .
14. , , .
15. , .
16. , .
5. .
: , . , .