, .
, .
, , , .
, . , .
a[0] | |
a[1] | -45 |
a[2] | |
a[3] | |
a[4] | |
a[5] | |
a[6] | |
a[7] |
8 . , , ([ ]). .
, .
, , . . , .
,
b=5. c=2,
a[b+c] +=2;
2 a[7].
, a,
cout << a[0] + a[1] + a[2] << endl;
a 2 x,
x=a[6] / 2;
, , ++ , .
() [ ] | ||
+ --! () | ||
* / % | ||
+ - | ||
<< >> | / | |
< <= > >= | ||
==!= | ||
&& | ||
|| | ||
?: | ||
= + = - = *= /= %= | ||
, | () |
. 4.2.
. , , , .
:
int a [12]; 12 .
.
:
int a [12], b[27];
. , char.
|
|
( , ):
int a [3] = {3,5,11}; int a [] = {3,8,54} , , .
- . , int a [3]={3,89}, .
int n [10] = {0};
.
, , .
,
int a [5] = {37,57,98,76,45,90}; - .
.4.5.
.
.
, .
,
char string1[ ] = first;
string1 first.
first .
\0.
.
char string1 = {f, i, r, s, t,,\0};
, , .
strng1[ 0 ] - f
strng1[ 3 ] - s.
, cin >>.
,
char string2 [20];
19 .
cin>>string2;
string2.
.
, , , , .
cin , , .
, , cout <<.
string2
cout << string2 << endl;
cout . , \0.
.
.
// 4.16
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
setlocale(LC_ALL, "rus");
const int arraySize = 10;
int a [arraySize] = {2, 6, 4, 8, 10, 12, 89, 68, 45, 37};
int i, hold;
cout << ""<<endl;
//
for (i = 0; i < arraySize; i++)
|
|
cout << setw(4)<< a[i];
//
//
for (int pass = 0; pass < arraySize - 1; pass++)
//
for (int j = 0; j < arraySize - 1; j++)
//
//
if (a[j] > a[ j + 1 ])
{hold = a[j];
a[j] = a[ j + 1 ];
a[ j + 1 ] = hold;
} // if
cout << "\n \n";
for (int k = 0; k < arraySize; k++)
cout << setw (4) << a[k];
cout << endl;
return 0; //
} // main
.4.16 a 10 . , . , () , , () . . . , . , .
for.
, .
hold = a[i];
a[i] = a[i+1];
a[i+1] = hold;
hold .
a[i] = a[i+1];
a[i+1] = a[i];
, , a[i] 7, a[i + 1] 5, 5, 7 . , .
.
. . .