9
Ͳ
Ͳ -
( 8)
: C++. .
1.
, , . ᒺ .
:
- ( );
- ( );
- ();
- ( );
- ( );
- ;
- ( ).
- . ³ . , , ( ). . ( ᒺ , , ).
++ - . , .
2. ()
ᒺ .
() , ( ) (). ( ) , . .
|
:
1. .
int Mas1[256]; // 256
void main(void)
{
double Mas2[100]; // 100 double
static char Mas3[20]; // 20
extern Mas1[]; // ,
int Mas4[3][4]; // int
|
|
}
[] , , , . ( ) . () 0, n-1, n .
(, ) . . - ( ), long . . .
:
- ( ) ;
- () ;
- ;
- .
. ( , ). , .
, - . . . , , ( ) .
9-1
, ( ) n (n ).
1. /* */
2. include<iostream.h>
3. #include<conio.h>
4. #include<math.h>
5. int main() //
6. {
7. clrscr(); //
8. double a,b,c; //
9. float d,x1,x2; //
10. /* */
11. cout<<"\n Programa obchislenia nerivnosti ax+bx+c>0 \n";
12. cout<<"\n\t\t Var.N2\n";
13. cout<<"\n Vykonav: Pradedov V.V.\n";
14. cout<<"\n";
15. cout<<"\n Vvedit znachinia nerivnosti: \n a=";
16. cin>>a; // ee
17. cout<<"\n b=";
18. cin>>b;
19. cout<<"\n c=";
20. cin>>c;
21. /*Oce */
22. b*=b;
23. d=(b-4)*a*c;
24. x1=-b+sqrt(d)/2*a;
25. x1=-b-sqrt(d)/2*a;
26. /* */
27. if (x1<0 || x2>0)
28. cout<<"\n Nerivnost mae rozviazok.";
29. if (x1>0 || x2<0)
30. cout<<"\n Nerivnost nemae rozviazku.";
31. getch(); // ( Enter).
32. return 0;
33. }
9-2
, (n × n) , :
|
|
#include<iostream.h>
#include<conio.h>
#include<math.h>
int x,y,x1,y1;
int main()
{
clrscr();
M: cout<<"Vvedite koordynaty damky:\n\tx= ";
cin>>x;
cout<<"\ty= ";
cin>>y;
cout<<"Vvedite koordynaty inshoi shashky:\n\tx= ";
cin>>x1;
cout<<"\ty= ";
cin>>y1;
//corectnost' danyh
if(x<0 || x>8 || y<0 || y>8) {
cout<<"Vvedit korektno dani!\n";
goto M;
}
//shashky na odniy pryamiy
if(x==x1 || y==y1) {
cout<<"Damka NE MOGE pobyty shashky!";
goto end;
}
//kray polya
if(x1==1 || x1==8 || y1==1 || y1==8) {
cout<<"Damka NE MOGE pobyty shashky!";
goto end;
}
if(abs(x-x1)==abs(y-y1)) { cout<<"Damka MOGE pobyty shashky:)"; }
else { cout<<"Damka NE MOGE pobyty shashky!"; }
end:
getch();
return 0;
}
9-3
.
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int x,y;
cout<<"\n Programa obchislenia nerivnosti ax+bx+c>0 \n";
cout<<"\n\t\t Var.N2\n";
cout<<"\n Vykonav: Pradedov V.V.\n";
cout<<"\n";
cout<<"\n Vvedit znachenia x,y:";
x1: cout<<"\n x=";
cin>>x;
if(x!=0 && x!=1 && x!=2 && x!=3){
cout<<"\n Vvedit concretno x";
goto x1;}
y1: cout<<"\n y=";
cin>>y;
if(y!=0 && y!=1 && y!=2 && y!=3){
cout<<"\n Vvedit concretno y";
goto y1;}
if(x==2 && y!=0) {cout<<"f=0";}
else if(x==2 &&y==0) {cout<<"\n f=1";}
switch(x){
case 0: switch(y){
case 0: cout<<"f=1";break;
case 1: cout<<"f=2";break;
case 2: cout<<"f=3";break;
case 3: cout<<"f=0";break;
}break;
case 1: switch(y){
case 0: cout<<"f=4";break;
case 1: cout<<"f=2";break;
case 2: cout<<"f=6";break;
case 3: cout<<"f=0";break;
}break;
case 3: switch(y){
case 0: cout<<"f=2";break;
case 1: cout<<"f=0";break;
case 2: cout<<"f=1";break;
case 3: cout<<"f=0";break;
}break;
}
getch();
return 0;
}