.


:




:

































 

 

 

 





, #include. ; h.

.

, .

y = sin (x); //

:

__ _ ( _,..., _)

{

_

}

, , , :

- , ;

- , , , .

9.1. , 65 "*" . , . : main() stars().

 

//

#include <iostream.h>

const int Limit=65;

void stars(void); // stars()

void main()

{ stars();

cout<<"Moscow Institute of Electronic Engineering"<<endl;

stars();

}

// stars()

void stars()

{ int count;

for (count=1; count<=Limit; count++)

putchar ('*');

putchar ('\n');

}

, .

.

9.2. space(), , .

#define address " Zelenograd"

#define name " Moscow Institute Electronic Engineering "

#define department " Informatics and Programming"

const int LIMIT=65;

#include <iostream.h>

void stars();

void space(int number);

void main()

{ int spaces;

stars();

space(25);

cout<<address<<endl;

spaces=(LIMIT - strlen(name))/2; // ,

//

space(spaces);

cout<<name<<endl;

space((LIMIT - strlen(department))/2); //

cout<<department<<endl;

stars();

}

// stars()

void stars()

{ int count;

for (count=1; count<=LIMIT; count++)

putchar ('*');

putchar ('\n');

}

// space()

void space(int number)

{ int count;

for (count=1; count <=number; count++)

putchar (' ');

}

number . . , - , - , .

, , :

void printnum (int i, int j)

{ cout<<" << i << j <<endl; }

; return.

return

, void .

9.3.

int abs(int x); // abs();

void main()

{ int =10, b=0, c= -22;

int d, e, f;

d= abs(a);

e= abs(b);

f= abs(c);

cout<<d<<e<<f<<endl;

}

int abs(int x) // ,

//

{ int y;

y= (x<0)? x: x;

return y; //

}

y= (x<0)? x: x

if (x<0) y= x;

else y= x;

abs(x):

int abs(int x)

{ if (x<0) return x;

return x;

}

abs(x):

int abs(int x)

{ if (x<0) return x;

return x;

cout<<" ";

cout <<endl;

cout<<" return.";

cout <<endl;

}

return , , , , , , .

, .

C, , , int. C++ , .

return , void ( main ()). , .

C++ .

, . ; , "".

, , , , . .

. , . var1 func(), var2 main().

9.4.

#include <iostrem.h>

void func(void)

{ int var1=11; // var1

cout<<"var1="<<var1<<endl;

}

int main(void)

{ int var2=22; // var2

cout<<"var2="<<var2<<endl;

func();

cout<<"var1="<<var1<<endl; //

//

return 0; // 'Undefined symbol var1'

}

, , . var1 func(), main(), .

9.5.

#include <iostream.h>

int var1=11; // var1

void func(void)

{ cout<<"var1="<<var1<<endl;

}

int main(void)

{ int var2=22;

cout<<"var2="<<var2<<endl;

func(); //

cout<<"var1="<<var1<<endl; // .

return 0;

}

. . , double . :

double SumOfData(double data[max]);

double SumOfData(double data[ ], int n);

SumOfData() n, , .

SumOfData() , , while, , return :

double SumOfData(double data[ ], int n)

{ double sum=0;

while (n>0)

sum += data [--n];

return sum;

}

.

ROWS - , COLS - . :

void AnyFn(int data[ROWS][COLS]);

void AnyFn(int data[ ][COLS]);

, :

void AnyFn(int data[ ][COLS], int numRows);

numRows data.

9.6.

#include <iostream.h>

#include <iomanip.h>

#include <stdlib.h>

const int COLS=8;

void FillArray(int data[ ][COLS], int numRows);

void DisplayTable(int data[ ][COLS], int numRows);

int data1[7][COLS];

int data2[4][COLS];

void main()

{ randomize(); //

FillArray(data1, 7);

DisplayTable(data1, 7);

FillArray(data2,4);

DisplayTable(data2,4);

}

void FillArray(int data[ ][COLS], int numRows)

{ int r, c;

for (r=0; r<numRows; r++)

for (c=0; c<COLS; c++)

data[r][c]= rand(50); // rand() -

}

void DisplayTable(int data[ ][COLS], int numRows)

{ int r, c;

for (r=0; r<numRows; r++)

{ cout<<endl;

for (c=0; c<COLS; c++)

cout<<setw(5)<<data[r][c]);

}

cout<<endl;

}

- , .

++ , , . , ++ .

:

"&" - ,

"*" - .

++, , .

:

_ _ (_*, __);

:

_ _ (_ *_, _)

{

// _

}

, , , .

, , , . , , .

, a b swp() .

9.7.

#include <iostream.h>

swp(int *x, int *y);

void main()

{ int a, b;

cout<< a b;

cin>>a>>b;

swp(&a, &b);

cout<< : a=<<a<<b=<<b;

}

void swp(int *x, int *y)

// x y , *x *y ,

{ int c;

c=*x;

x= y;

*y=c;

}

9.8. , . . , return.

:

cout<< <<mean (numbs, size)<<endl;

/* n .*/

int mean (int array [ ], int n)

{ int index;

long sum; /* , , long int */.

If (n>0)

{ for (index=0, sum=0; index<n; index++)

sum+=array [index];

return sum/n; // int.

}

else

{ cout<< .<<endl;

return 0;

}

}

. iPtr int array[index] : *(iPtr+index).





:


: 2017-03-18; !; : 638 |


:

:

, .
==> ...

1913 - | 1742 -


© 2015-2024 lektsii.org - -

: 0.039 .