.


:




:

































 

 

 

 


2.




1. 10 . , .

#include <stdio.h>

#include <cstdlib>

 

int main()

{

int arr[10]; // arr 10

int i; //

 

for (i = 0; i < 10; i++) //

{

printf(" %d : ", i);

scanf("%d",&arr[i]);

}

 

for (i = 1; i <= 8; i++) // 1 8

{

/* . , */

if(arr[i] > arr[i-1] && arr[i] > arr[i+1])

printf("\n %d : %d\n",i,arr[i]);

}

system("pause");

}

 

0 : 1

1 : 3

2 : 4

3 : 5

4 : 2

5 : 8

6 : 6

7 : 10

8 : 5

9 : 1

 

3 : 5

5 : 8

7 : 10

 

2. , .

#include <stdio.h>

#include <cstdlib>

#include <string.h>

 

int main()

{

int i;

char z; //

printf (\n :\n);

/* . , , */

for (i = 0, z = 'a'; z!= '.'; i++) {

scanf ("%c", &z);

if (z == '0' || z == '1' || z == '2' || z == '3' || z == '4') continue;

if (z == '5' || z == '6' || z == '7' || z == '8' || z == '9') continue;

printf ( : );

printf ("%c\n", z);

}

system ("pause");

}

 

:

23680 769 25 807 3664

 

:

 

3. , ?

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

 

typedef struct

{

float x;

float y;

float z;

float R;

} shar;

 

typedef struct

{

float x;

float y;

float z;

} tochka;

 

int main()

{

shar S;

tochka T;

printf ("\n : x,y,z,R ");

scanf ("%f %f %f %f",&S.x,&S.y,&S.z,&S.R);

printf ("\n :x,y,z ");

scanf ("%f %f %f", &T.x,&T.y,&T.z);

 

if ((T.x-S.x)*(T.x-S.x)+(T.y-S.y)*(T.y-S.y)+(T.z-S.z)*(T.z-S.z)<=S.R*S.R)

printf ("\n !");

else

printf ("\n !");

 

getch();

}

 

: x,y,z,R 0 0 0 2

 

:x,y,z 1 1 1

 

!

 

4. .

#include <stdio.h>

#include <stdlib.h>

#include <iostream.h>

#include <math.h>

 

//

int m,n;

int* ostatki;

int* period;

unsigned int len;

 

//

int IsInOstatki(int ost, int len)

{

//len-1 ,

for (int i = 0; i < len - 1; i++)

{

if (ostatki[i] == ost) return i;

}

return 0;

}

 

int main()

{

cout << " : \r";

cin >> m;

cout << "\r\n : \r";

cin >> n;

ostatki = new int[n+1];

period = new int[n+1];

 

int d = m, q = n;

int r, pos;

len = 1;

 

do

{

r = d % q;

ostatki[len] = r;

d /= q;

period[len] = d;

 

d = 10 * r;

len++;

}

while ((pos = IsInOstatki (r, len/* */)) == 0);

 

//

cout << "= \r\n";

cout << period[1] << ",";

for (r = 2; r < len; r++)

{

cout << period[r];

}

cout << "\r\n = ";

for(r = pos + 1; r < len; r++)

cout << period[r];

 

cout << "\r\n";

 

//

delete[] ostatki;

delete[] period;

 

system ("pause");

}

:

 

:

0,923076

= 923076

 

5. .

, , 100 , . 400, . , 2000 . , 400 .

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <conio.h>

 

int main()

{

int Temp;

int DaysInMonth[2][12]= // 0-, 1 -

{{31,28,31,30,31,30,31,31,30,31,30,31},

{31,29,31,30,31,30,31,31,30,31,30,31}

};

 

//

int CurrentYear, Diff, Day1, Day2, Month1, Month2, i, Visokos;

printf("\n : ");

scanf("%d",&CurrentYear);

printf(" %d. \n",CurrentYear);

 

//

if(CurrentYear%400==0 || (CurrentYear%4==0 && CurrentYear%100!=0))

{

printf("\n !\n\n"); Visokos=1;

}

else

{

printf("\nNE Visokosny god!\n\n"); Visokos=0;

}

 

do

{

printf(" 1 (1-31):");

scanf("%d",&Day1);

printf(" 1 (1-12):");

scanf("%d",&Month1);

}

while ((Month1<1||Month1>12)||(Day1<1||Day1>DaysInMonth[Visokos][Month1-1]));

 

do

{

printf(" 2 (1-31): ");

scanf("%d",&Day2);

printf(" 2 (1-12): ");

scanf("%d",&Month2);

}

while ((Month2<1||Month2>12)||(Day2<1||Day2>DaysInMonth[Visokos][Month2-1]));

 

if(Month1>Month2)

{ //

Temp=Month1;Month1=Month2;Month2=Temp; //

Temp=Day1;Day1=Day2;Day2=Temp;

}

Diff=0; //

if (Month1==Month2) Diff=abs(Day1-Day2); //

else

{

for (i=Month1;i<Month2-1;i++) //

Diff += DaysInMonth[Visokos][i]; //

Diff+=(DaysInMonth[Visokos][Month1-1]-Day1);//

Diff+=Day2; //

}

 

//

printf (" %d.%d.%d %d.%d.%d",Day1,Month1,CurrentYear,Day2,Month2, CurrentYear);

printf ("\n = %d \n",Diff);

getch();

}

 

: 2008

2008.

 

!

 

1 (1-31):3

1 (1-12):10

2 (1-31): 12

2 (1-12): 10

3.10.2008 12.10.2008

= 9

 

6.

- , . .

, . . . . .

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <conio.h>

#define M 13

 

int main()

{

int n;

int a[M][M];

int i, j, k;

 

do

{

printf (" n < 12: ");

scanf("%d", &n);

}

while (n >= 12);

 

puts (" 1");

 

for (i = 0; i <= n; i++)

{

for (j = 0; j <= i; j++)

{

if ((i == j) || (j == 0)) a[i][j] = 1;

else a[i][j] = a[i-1][j-1] + a[i-1][j];

printf ("%4d", a[i][j]);

}

printf ("\n");

}

 

Puts (" 2");

 

for (i = 0; i <= n; i++)

{

for (j = 0;j <= i; j++)

{

if (j == 0)

for (k = 0; k < (n-i); k++) printf (" ");

 

printf ("%6d", a[i][j]);

}

printf ("\n");

}

 

getch ();

}

 

n < 12: 7

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

1 6 15 20 15 6 1

1 7 21 35 35 21 7 1

 

2

1 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

1 6 15 20 15 6 1

1 7 21 35 35 21 7 1

 

7. : , .

#include <stdio.h>

#include <time.h>

#include <stdlib.h>

#include <conio.h>

#include <math.h>

 

inline void Change(int a[], int first, int second)

// first second

// a[] -

// first second - a, !

{

if (first == second) // ,

return;

int i;

 

i = a[second];

a[second] = a[first];

a[first] = i;

}

 

int FindMax(int a[], int max)

// a[0] a[max]

// a[] -

// max - a

{

int imax = 0;

 

for (int i = 0; i <= max; i++)

{

if (a[imax] < a[i]) imax = i;

}

 

return imax;

}

 

void SelectSort(int b[], int max)

//

// b[] -

// max - b

{

int i1;

for (int i = max - 1; i > 0; i--)

{

i1 = FindMax(b, i); // a[0] a[i]

Change(b, i, i1); // ( i)

}

}

 

void BubbleSort(int c[], int max)

// ""

// c[] -

// max - c

{

for (int i1 = 0; i1 < max; i1++)

{

for (int i = max-2; i >= i1; i--)

{

if (c[i+1] > c[i]) continue;

Change(c, i, i+1); // ,

}

}

}

 

void InsertSort(int d[], int max)

//

// d[] -

// max - c

{

int temp, j;

for (int i = 1; i < max; i++) // , i -

{

temp = d[i];

j = i - 1; //

while (j >= 0 && d[j] > temp)

{

d[j+1] = d[j]; // ,

--j;

}

// ,

d[j+1] = temp;

}

}

 

int main()

{

int MAX;

 

printf(" : ");

scanf("%i", &MAX);

//

int *a = new int[MAX];

int *b = new int[MAX];

int *c = new int[MAX];

int *d = new int[MAX];

 

srand((unsigned)time(0));

for (int i = 0; i < MAX; i++)

{

a[i] = rand(); //

b[i] = a[i]; //

c[i] = a[i]; //

d[i] = a[i]; //

}

 

clock_t begin, end;

 

begin = clock();

BubbleSort(b, MAX); // ""

end = clock();

 

float f0 = (float)(end-begin); // , ""

printf ("\n %i "" \t%.0f msec.\r\n", MAX, f0);

 

begin = clock();

SelectSort(c, MAX); // b

end = clock();

 

float f1 = (float)(end-begin); // ,

printf (" %i \t%.0f msec.\r\n", MAX, f1);

 

begin = clock();

InsertSort(d, MAX); // b

end = clock();

 

float f2 = (float)(end-begin); // ,

printf (" %i \t%.0f msec.\r\n", MAX, f2);

 

// ?

printf("\r\n\r\n\r\n ? (y/n)");

short Key = 0;

 

while (Key = _getch()) //

{

if (Key == 'n' || Key == 'N' || Key == 27) // N Esc,

return 0; //

else if (Key == 'y' || Key == 'Y') // y,

break; //

}

 

printf("\r\n\r\n\r\n\r\n");

printf(" N.\t \tN.\t \tN.\t \tN.\t \r\n");

printf("\r\n");

for (int i = 0; i < MAX; i++)

printf("%3i.\t%5i\t%3i.\t%5i\t%3i.\t%5i\t%3i.\t%5i\r\n",

i+1, a[i], i+1, b[i], i+1, c[i], i+1, d[i]); //

printf("\r\n \r\n");

 

Key = 0;

 

while (!Key) Key = _getch(); //

}

 

: 10000

 

10000 "" 1139 msec.

10000 175 msec.

10000 113 msec.

 

? (y/n)

 

N. N. N. N.

 

1. 30410 1. 1072 1. 1072 1. 1072

2. 7475 2. 1219 2. 1219 2. 1219

3. 13312 3. 1405 3. 1405 3. 1405

4. 30386 4. 1911 4. 1911 4. 1911

5. 27070 5. 3080 5. 3080 5. 3080

6. 11743 6. 6686 6. 6686 6. 6686

7. 23967 7. 6981 7. 6981 7. 6981

8. 7718 8. 7229 8. 7229 8. 7229

9. 24750 9. 7457 9. 7457 9. 7457

10. 29293 10. 7475 10. 7475 10. 7475

...................................

 

8. .

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <conio.h>

#include <iostream>

#include <windows.h>

using namespace std;

 

 

class Node

{

public:

int number;

Node* next;

};

 

int main()

{

 

Node* head = NULL;

Node* lastPtr = NULL;

short action = -1;

while (1)

{

printf("1. \n");

printf("2. \n");

printf("3. \n");

printf("4. \n");

printf("5. \n");

printf("0. \n\n");

printf(" : ");

cin>>action;

if (action == 0)

{

system("CLS");

break;

}

 

if (action == 1)

{

system("CLS");

Node* ptr = new Node;

int numb = -1;

printf(" : ");

cin>>numb;

ptr->number = numb;

ptr->next = NULL;

if (head == 0)

{

head = ptr;

lastPtr = ptr;

system("CLS");

continue;

}

lastPtr->next = ptr;

lastPtr = ptr;

system("CLS");

continue;

}

 

if (action == 2)

{

Node* ptr = NULL;

system("CLS");

if (head == NULL)

{

printf("\t!!! !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

printf("* * * * * * * * * *\n\n");

ptr = head;

while (1)

{

cout<<ptr->number<<" ";

if (ptr->next == 0)

break;

ptr = ptr->next;

}

cout<<"\n\n";

system("PAUSE");

system("CLS");

continue;

}

 

if (action == 3)

{

Node* ptr = NULL;

int key = -1;

system("CLS");

if (head == NULL)

{

printf("\t!!! !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

printf(" : ");

cin>>key;

ptr = head;

while (1)

{

if (key == ptr->number)

{

printf("\n\t!!! !!!\n");

break;

}

if (ptr->next == NULL)

{

printf("\n\t!!! !!!\n");

break;

}

ptr = ptr->next;

}

system("PAUSE");

system("CLS");

continue;

}

 

if (action == 4)

{

system("CLS");

Node* ptrDelete = NULL;

if (head == NULL)

{

printf("\t!!! !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

if (head->next == NULL)

{

head = NULL;

delete head;

continue;

}

ptrDelete = head;

head = ptrDelete->next;

delete ptrDelete;

continue;

}

 

if (action == 5)

{

system("CLS");

Node* ptrPrev = NULL;

Node* ptrDelete = NULL;

int key = -1;

if (head == NULL)

{

printf("\t!!! !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

printf(" : ");

cin>>key;

ptrDelete = head;

if (ptrDelete->number == key)

{

head = ptrDelete->next;

delete ptrDelete;

system("CLS");

continue;

}

while (1)

{

if (key == ptrDelete->number)

{

ptrPrev->next = ptrDelete->next;

delete ptrDelete;

break;

}

if (ptrDelete->next == 0)

{

printf("\n\t!!! !!!\n");

system("PAUSE");

break;

}

ptrPrev = ptrDelete;

ptrDelete = ptrDelete->next;

}

system("CLS");

continue;

}

 

if (action > 5)

{

system("CLS");

printf("\t!!! . !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

}

}

 

( )

1.

 

2.

 

3.

 

4.

 

5.

 

0.

 

 

:

 

9. .

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <conio.h>

#include <iostream>

#include <windows.h>

using namespace std;

 

class Node

{

public:

int number;

Node* next;

Node* last;

};

 

void main()

{

short action = -1;

Node* head = NULL;

Node* tail = NULL;

Node* ptrLast = NULL;

 

while (1)

{

puts("1. \n");

puts("2. \n");

puts("3. \n");

puts("4. \n");

puts("5. \n");

puts("6. \n");

puts("0. \n\n");

puts(" : ");

cin>>action;

 

if (action == 0)

{

system("CLS");

break;

}

 

if (action == 1)

{

system("CLS");

int numb = -1;

puts(" : ");

cin>>numb;

Node* ptr = new Node;

ptr->number = numb;

ptr->next = NULL;

tail = ptr;

if (head == NULL)

{

head = ptr;

ptrLast = ptr;

ptr->last = NULL;

system("CLS");

continue;

}

ptr->last = ptrLast;

ptrLast->next = ptr;

ptrLast = ptr;

system("CLS");

continue;

}

 

if (action == 2)

{

system("CLS");

Node* ptr = NULL;

if (head == NULL)

{

puts("\t!!! !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

puts("* * * * * : * * * * *\n\n");

ptr = head;

while (1)

{

cout<<ptr->number<<" ";

if (ptr->next == 0)

break;

ptr = ptr->next;

}

cout<<"\n\n";

system("PAUSE");

system("CLS");

continue;

}

 

if (action == 3)

{

system("CLS");

Node* ptr = NULL;

if (head == NULL)

{

puts("\t!!! !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

puts("* * * * * : * * * * *\n\n");

ptr = tail;

while (1)

{

cout<<ptr->number<<" ";

if (ptr->last == 0)

break;

ptr = ptr->last;

}

cout<<"\n\n";

system("PAUSE");

system("CLS");

continue;

}

 

if (action == 4)

{

system("CLS");

Node* ptrDelete = NULL;

if (head == NULL)

{

puts("\t!!! !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

if (head->next == NULL)

{

head = NULL;

tail = NULL;

delete head;

continue;

}

ptrDelete = head;

head = ptrDelete->next;

head->last = NULL;

delete ptrDelete;

continue;

}

 

if (action == 5)

{

system("CLS");

Node* ptrDelete = NULL;

if (tail == NULL)

{

puts("\t!!! !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

if (tail->last == NULL)

{

head = NULL;

tail = NULL;

delete tail;

continue;

}

ptrDelete = tail;

tail = ptrDelete->last;

tail->next = NULL;

ptrLast = tail;

delete ptrDelete;

continue;

}

 

if (action == 6)

{

system("CLS");

Node* ptr = NULL;

int key = -1;

if (head == NULL)

{

puts("\t!!! !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

puts(" : ");

cin>>key;

ptr = head;

while (1)

{

if (key == ptr->number)

{

puts("\n\t!!! !!!\n");

break;

}

if (ptr->next == NULL)

{

puts("\n\t!!! !!!\n");

break;

}

ptr = ptr->next;

}

system("PAUSE");

system("CLS");

continue;

}

 

if (action > 6)

{

system("CLS");

puts("\t!!! . !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

}

}

 

( )

1.

 

2.

 

3.

 

4.

 

5.

 

6.

 

0.

 

 

:

 

10. .

class Node

{

public:

int number;

Node* last;

Node* next;

};

 

int main()

{

 

Node* head = NULL;

Node* tail = NULL;

Node* ptrLast = NULL;

short action = -1;

 

while(1)

{

printf("1. \n");

printf("2. \n");

printf("3. \n");

printf("4. \n");

printf("0. \n\n");

printf(" : ");

cin>>action;

 

if (action == 0)

{

system("CLS");

break;

}

 

if (action == 1)

{

system("CLS");

int numb = -1;

printf(" : ");

cin>>numb;

Node* ptr = new Node;

ptr->number = numb;

ptr->next = NULL;

tail = ptr;

if (head == NULL)

{

head = ptr;

ptrLast = ptr;

ptr->last = NULL;

system("CLS");

continue;

}

ptr->last = ptrLast;

ptrLast->next = ptr;

ptrLast = ptr;

system("CLS");

continue;

}

 

if (action == 2)

{

system("CLS");

Node* ptr = NULL;

if (head == NULL)

{

printf("\t!!! !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

printf("* * * * * * * * * *\n\n");

ptr = tail;

while (1)

{

cout<<ptr->number<<" ";

if (ptr->last == 0)

break;

ptr = ptr->last;

}

cout<<"\n\n";

system("PAUSE");

system("CLS");

continue;

}

 

if (action == 3)

{

system("CLS");

Node* ptrDelete = NULL;

if (head == NULL)

{

printf("\t!!! !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

if (head->next == NULL)

{

head = NULL;

tail = NULL;

delete tail;

continue;

}

ptrDelete = head;

head = ptrDelete->next;

head->last = NULL;

delete ptrDelete;

continue;

}

 

if (action == 4)

{

system("CLS");

Node* ptr = NULL;

int key = -1;

if (head == NULL)

{

printf("\t!!! !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

printf(" : ");

cin>>key;

ptr = head;

while (1)

{

if (key == ptr->number)

{

printf("\n\t!!! !!!\n");

break;

}

if (ptr->next == NULL)

{

printf("\n\t!!! !!!\n");

break;

}

ptr = ptr->next;

}

system("PAUSE");

system("CLS");

continue;

}

 

if (action > 4)

{

system("CLS");

printf("\t!!! . !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

}

 

 

}

 

( )

1.

 

2.

 

3.

 

4.

 

0.

 

 

:

 

11. .

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <conio.h>

#include <iostream>

#include <windows.h>

using namespace std;

 

class Node

{

public:

int number;

Node* last;

};

 

int main()

{

 

Node* ptrLast = NULL;

Node* top = NULL;

short action = -1;

 

while (1)

{

printf("1. \n");

printf("2. \n");

printf("3. \n");

printf("4. \n");

printf("0. \n\n");

printf(" : ");

cin>>action;

 

if (action == 0)

{

system("CLS");

break;

}

 

if (action == 1)

{

system("CLS");

int numb = -1;

printf(" : ");

cin>>numb;

Node* ptr = new Node;

ptr->number = numb;

if (top == NULL)

{

ptr->last = NULL;

top = ptr;

ptrLast = ptr;

system("CLS");

continue;

}

top = ptr;

ptr->last = ptrLast;

ptrLast = ptr;

system("CLS");

continue;

}

 

if (action == 2)

{

system("CLS");

Node* ptrDelete = NULL;

if (top == NULL)

{

printf("\t!!! !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

ptrDelete = top;

if (ptrDelete->last == NULL)

{

top = NULL;

delete ptrDelete;

system("CLS");

continue;

}

top = ptrDelete->last;

ptrLast = top;

delete ptrDelete;

continue;

}

 

if (action == 3)

{

system("CLS");

if (top == NULL)

{

printf("\t!!! !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

printf(" : ");

cout<<top->number<<"\n\n";

system("PAUSE");

system("CLS");

continue;

}

 

if (action == 4)

{

system("CLS");

Node* ptr = NULL;

if (top == NULL)

{

printf("\t!!! !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

printf("* * * * * * * * * *\n\n");

ptr = top;

while (1)

{

cout<<ptr->number<<endl;

if (ptr->last == NULL)

{

system("PAUSE");

system("CLS");

break;

}

ptr = ptr->last;

}

}

 

if (action > 4)

{

system("CLS");

printf("\t!!! . !!!\n\n");

system("PAUSE");

system("CLS");

continue;

}

 

}

 

}

 

( )

1.

 

2.

 

3.

 

4.

 

0.

 

 

:

 

12. .

XIX . , , . , . , .

, 1883 . (Claus) -- (Li-Sou-Stian), , - - (Lucas) - (Saint Louis).





:


: 2016-10-22; !; : 1359 |


:

:

, .
==> ...

1376 - | 1151 -


© 2015-2024 lektsii.org - -

: 0.668 .