Сформулировать, что выполняют программы
21.12.2018, 18:37. Показов 353. Ответов 0
Сформулировать, что делают программы и если есть ошибки, пожалуйста, помогите исправить
Первая:
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| #include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{float y[10],min,max;
int i,nmin,nmax,n;
cout<<" vvedite chislo elementov massiva";cin>>n;
cout<<"vvedite chisla cherez probel"<<endl;
for(i=0;i<n;i++) cin>>y[i];
min=y[0];
max=y[0];
for(i=0;i<n;i++) {
if(y[i]<min) {min=y[i];nmin=i;}
if(y[i]>max) {max=y[i];nmax=i;}
}
cout<<"min="<<min<<endl;
cout<<"nmin="<<nmin<<endl;
cout<<"max="<<max<<endl;
cout<<"nmax="<<nmax;
cout<<"\n press <enter> ";
getch();
} |
|
Вторая:
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| //vichislenie NOD
#include<iostream.h>
#include<conio.h>
#include<math.h>
int fnod(int a,int b)
{
int aa,bb,r,nod;
aa=a;bb=b;
r=aa%bb;
while(r)
{
aa=bb;
bb=r;
r=aa%bb;
}
nod=bb;
return nod;
}
void main()
{
int y[100],a,b,nod,n,i;
cout<<" vvedite chislo elementov massiva n= ";cin>>n;
cout<<" vvedite massiv po strokam"<<endl;
for(i=0;i<n;i++) cin>>y[i];
a=y[0];
for(i=1;i<n;i++)
{
b=y[i];
nod=fnod(a,b);
a=nod;
}
cout<<" nod= "<<nod<<endl;
cout<<"\n press <enter>";
getch();
} |
|
Третья:
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| #include<iostream.h>
#include<conio.h>
#include<math.h>
main()
{float y[5][5],s[5];
int i,j,m,n,k,l;
cout<<" vvedite chislo strok massiva m= ";cin>>m;
cout<<" vvedite chislo stolbsov massiva n= ";cin>>n;
cout<<"vvedite massiv po strokam"<<endl;
for(i=0;i<m;i++)
{
cout<<"->"<<endl;
for(j=0;j<n;j++)
cin>>y[i][j];
}
cout<<" vvedennii massiv y"<<endl;
for(i=0;i<m;i++)
{
cout<<""<<endl;
for(j=0;j<n;j++)
cout<<y[i][j]<<" ";
}
//
for(i=0;i<n;i++) s[i]=0;
//
//
for(i=0;i<m;i++) {
for(j=0;j<n;j++)
if((i==j) && (y[i][j]>0)) {
k=i;for(l=0;l<n;l++) s[k]+=y[l][k];}
}
//
cout<<""<<endl;
cout<<"rezultat s= ";
for(i=0;i<n;i++) cout<<s[i]<<" ";
cout<<"\n press <enter> ";
getch();
} |
|
Четвертая:
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| #include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
double x, y, K, A, B, C, D;
int x2, y2;
int main(void) {
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
A =-2.7; B=-0.9; C=-0.86; D=-2.20;
setcolor(getmaxcolor());
while (!kbhit()) {
K = x;
x=sin(A*y) - cos(B*x);
y=sin(C*K) - cos(D*y);
x2 = ceil(x * 120) + 350;
y2 = ceil(y * 120) + 210;
putpixel(x2, y2, getpixel(x2, y2)+1);
}
getch();
closegraph();
return 0;
} |
|
Пятая:
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
| #include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
int i, m, c;
float x, y, x1, y1;
float a[25], b[25];
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "D:\\BC31\\BGI");
/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
x=1; y=1; m=5; //m = 3,4,5
setcolor(RED);
for(i=0; i < m; i++)
{
a[2*i] = cos(2*M_PI * (i+1) / m);
b[2*i] = sin(2*M_PI * (i+1) / m);
a[2*i+1] = 0.5*(cos(2*M_PI * (i+1) / m) + cos(2*M_PI * i / m));
b[2*i+1] = 0.5*(sin(2*M_PI * (i+1) / m) + sin(2*M_PI * i / m));
}
randomize();
do
{
c = random(2*m);
x1 = (x/(x*x + y*y))/3 + a[c];
y1 = (-y/(x*x + y*y))/3 + b[c];
x = x1 / (x1*x1 + y1*y1);
y = y1 / (x1*x1 + y1*y1);
putpixel(ceil(x*70+320), ceil(y*70+240), RED);
} while (!kbhit());
getch();
closegraph();
return 0;
} |
|
Шестая:
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
| #include <math.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
void axes(){
int maxx,maxy,midx,midy;
int x,y,i=0;
char s[100];
maxx = getmaxx(); midx=maxx/2;
maxy = getmaxy(); midy=maxy/2;
setcolor(15);
setlinestyle(0,0,0);
line(0,midy,maxx,midy);
line(midx,0,midx,maxy);
for(x=midx;x>=0;x-=25) {line(x,midy-3,x,midy+3);
sprintf(s,"%d",i); outtextxy(x-10,midy+6,s);i--;}i=1;
for(x=midx;x<=maxx;x+=25){line(x,midy-3,x,midy+3);
sprintf(s,"%d",i); outtextxy(x+20,midy+6,s);i++;}i=1;
for(y=midy;y>=0;y-=25){line(midx-3,y,midx+3,y);
sprintf(s,"%d",i); outtextxy(midx+15,y-30,s);i++;} i=-1;
for(y=midy;y<=maxy;y+=25){ line(midx-3,y,midx+3,y);
sprintf(s,"%d",i); outtextxy(midx-15,y+15,s);i--;}}
void draw(){
int R1,R2,r,choice;
int maxx,maxy,midx,midy,x,y;
srand(time(NULL));
maxx = getmaxx(); midx=maxx/2;
maxy = getmaxy(); midy=maxy/2;
TOP:
system("cls"); //очистка текстового меню
printf(" 1)Ввести R1 R2 и центр x,y \n 2)Определить R1 R2 center автоматически\n 3)Почистить экран\n 4)Выход\n");
scanf("%d",&choice);
switch(choice){
case 1:
printf("Введите R1 R2 центр x y\n");
scanf("%d %d %d %d",&R1,&R2,&x,&y);R1=R1*25;R2=R2*25;x=midx+(x*25); y=midy-(y*25);
break;
case 2:
printf("R1 R2 center определился автоматически\n");
R1=rand()%15; R2=rand()%10; x=-10+rand()%15; y=-10+rand()%15;
R1=R1*25;R2=R2*25;x=midx+(x*25); y=midy-(y*25);
break;
case 3:
cleardevice();
axes();
goto TOP;
case 4:
exit(1);}
r=rand()%12;
setcolor(r);
setlinestyle(0,0,3);
circle(x,y,R1);
circle(x,y,R2);
line(x+R2,y,x+R1,y);line(x-R2,y,x-R1,y);
line(x,y+R2,x,y+R1);line(x,y-R2,x,y-R1);
goto TOP;}
int main (){
int graphdriver = DETECT,gmode,errorcode;
int maxx,maxy,midx,midy;
initgraph(&graphdriver,&gmode,"");
errorcode=graphresult();
if(errorcode!=grOk){
printf("Error:%s\n",grapherrormsg(errorcode));
printf("Press any key to stop\n");
getch();
exit(1);}
maxx = getmaxx(); midx=maxx/2;
maxy = getmaxy(); midy=maxy/2;
axes();
draw();
getch();
closegraph();
return 0;} |
|
0
|