2.2. k m, p , . u=(k-m2)/(p+k+m), k, m, p, u : 15 ; 1 , , .
2.3. j u, m , ;. l=(j+u-m)/(ju-m2), j, u, m, l : 8 ; 5 , , .
2.4. 4 , . : 3 , , .
2.5. a, b, c, /;. k=(a+b+c), a, b , k : 8 , 4 , , .
2.6. 6 , . : , , 5 , , /.
2.7. 4 , . : , 6 , , .
2.8. // . : , .
2.9. a, b, c, -. d=(a2+b2)/c. : , , 10 , 5 , , .
2.10. 6 , . : , 20 , , .
3. Ͳ
3.1. -.
3.2. -.
3.3. ,
3.4. - .
3.5. .
|
|
11
Ͳֲ IJ ² "Ѳ"
"Ѳ" .
1. Ͳ ²Ҳ
1.1. "ѳ" if.
if (<>) <1>; else <2>;
<>, if, , < 1>, < 2>. Else < 2> . , {}.
1. a b. .
#include <stdio.h>
main()
{int a,b;
puts("Input a and b");
/* a b*/
scanf("%d %d",&a,&b);
if (a>b) puts ("a>b");
else {if (a==b) puts ("a=b");
else puts("a<b");}
}
2. y={ax2+bx+c, x>2; ax2-bx+c, x<2; a+b+c, x=2;}.
#include <stdio.h>
main()
{int a,b,c,x,y;
printf("\nInput a b c x\n");
/* a b c x*/
scanf("%d %d %d %d",&a,&b,&c,&x);
if (x>2) y=a*x*x+b*x+c;
else {if (x<2) y=a*x*x-b*x+c;
else y=a+b+c;}
printf("y=%d",y);
}
1.2. switch. ³ :
Switch ()
{
case _1: _1;
case _2: _2;
case _n: _n;
Default:
}
switch _1, _2,, _n, . , , default.
3. . a, (+ -, *, %) ( char). switch .
#include <stdio.h>
main()
{int a,b,y;
char znak;
printf("\n\tInput a, + or - or * or %, b (without spaces between symbols\n\n");
/* a, + - * %, b ( )*/
scanf("%d%c%d",&a,&znak,&b);
switch(znak)
{case '+': y=a+b; break;
case '-': y=a-b; break;
case '*': y=a*b; break;
case '%': y=a%b; break;
default: printf("Error"); break;}
if((znak=='+')||(znak=='')||(znak=='*')||
(znak=='%')) printf("a%cb=%d",znak,y);
}
2.
"Ѳ", .
2.1. , , 4, , , 2. , , , 3.5.
2.2. , AX2+BX+C=0, . , , .
|
|
2.3. , , A1X+B1Y+C1=0 2X+B2Y+C2=0.
2.4. , , , Y1=K1X+B1, Y2=K2X+B2.
2.5. BCD (X1;Y1) (X2;Y2), . , K (Xk;Yk) .
2.6. (Xa;Ya), R1 R2 . , B (XB;YB) .
2.7. BCD (X1;Y1) (X2;Y2), . , K (X3;Y3), .
2.8. , . . .
2.9. (XC;YC) R. , (XA;YA) , α1, α2.
2.10. ABC, A (XA;YA), B (XB;YB), C (XC;YC). , D (XD;YD) .
3. Ͳ
3.1. .
3.2. .
3.3. else.
3.4. default.
3.5. switch break.
12
Ͳֲ ˲ ² "Ѳ"
"Ѳ" .
1. Ͳ ²Ҳ
1.1. , for. :
for(<1>;<2>;<3>)< >;
1 ; 2 ; 3 .
- for . , .
:
for(;;) < >;
, {}.
1. for Electrical Drive, n!=1*2*3*4**n, .
#include <stdio.h>
main()
{int i,j=1,n;
printf("\n");
for(i=1;i<=3;i++)printf("Electrical Drive\t");
printf("\nInput value of n\n");
/* n*/
scanf("%d",&n);
for(i=1;i<=n;i++) j*=i;
printf("n!=%d",j);
j=1;
printf("\n");
for(i=1;i<=n;i++)printf("%d\t",(j*=i));}
1.2. , , while. :
while(<>) < >;
ҳ , .
2. , R , while.
#include <stdio.h>
main()
{int i=1;
printf("\nInput string of symbols\n");
/* */
while((getchar())!='R')i++;
printf("Symbol R is %d",i);
/* R */
}
1.3. do-while, for while, , . , do-while . :
|
|
do < > while(<>);
3. , R , do while.
#include <stdio.h>
main()
{int i=0;
printf("\nInput string of symbols\n");
/* */
do i++;
while((getchar())!='R');
printf("Symbol R is %d",i);
/* R */
}
1.4. for, while, do-while break continue, if. break , continue .
1.5. "ѳ" goto, :
goto <>;
, , , :
<>:<>;
, goto , ;
4. , 1 9
#include <stdio.h>
int main(void)
{int i;
i = 1;
again:
printf("%d ", i);
i++;
if(i<10)goto again;
return 0;
}
2.
"ѳ", .
2.1. n- . . , 1. .
2.2. n- . . 䒺 , 1. .
2.3. n- . . , 1.
2.4. n- . . , 1.
1 1 1 1
2.5. - 0 2π, 0.05. , , .
2.6. - 0 π, 0.02. , , .
2.7. - 0 10, 0.1. , , .
2.8. - 0 20, 0.4. , , .
2.9. - 0 1, 0.01. , , .
2.10. - 0 5, 0.1. , , .
|
|
3. Ͳ
3.1. , .
3.2. , .
3.3. .
3.4. .
3.5. while do-while.
13
̲Ͳ ̲Ͳ ² "Ѳ"
Ѳ.
1. Ͳ ²Ҳ
1.1. , , , . , , , [], :
int a[100];
char b[30];
0: a[0], a[1], ,a[n-1]. , 0 99.
, , ,
char a[10][20];
, . , , , , [5][9] , 6 , 10 .
1.2. . - , , . :
int a[5];
5 a[0], a[1], a[2], a[3], a[4].
int *y; , y=&a[0]; a[0]. , y=&a[0]; y=a;.
a[i] *(a+i). y , y[i] *(y+i).
̳ . . y=a; y++;. . a=y; a++; z=&a; , .
. - NULL, 0. . , .
1. 10 , , .
#include <stdio.h>
main()
{int m[10],i,n,k,ind;
puts("\nInput string of 10 integer through the spaces");
/* 10 */
for(i=0;i<10;i++)
scanf("%d",&m[i]);
for(n=9;n>=0;n--)
{k=-32768; /* */
for(i=0;i<=n;i++)
if(m[i]>k)
{k=m[i];ind=i;}
m[ind]=m[n];m[n]=k;
}
puts("Constructed string");/* */
for(i=0;i<10;i++) printf("%d ",m[i]);
}
. 10 10 . 10- . 9 . , .
2. ' . . . . 1.1.
. 1.1.
#include <stdio.h>
main()
{int i,j,q,ind[5]={0,0,0,0,0};
char p, s[5][20], *m[5];
printf("\nInput 5 raws of symbols\n");
/* 5 */
for(i=0;i<5;i++){printf("Input raw\n");
/* */
scanf("%s",s[i]);
m[i]=&s[i][0];}
for(i=0;i<5;i++)
printf("Raw %d address of raw - %p\t%s\n",i,m[i],m[i]);
/* , */
for(i=0;i<5;i++)
{p='A';q=0;
for(j=0;j<5;j++)
if (s[j][0]>=p && ind[j]==0)
{p=s[j][0]; q=j;}
ind[q]=1;
m[i]=&s[q][0];}
puts("\nOrdered raws");/* */
|
|
for(i=0;i<5;i++)
printf("Raw %d\t%p\t%s\n",i,m[i],m[i]);
/* , */}
2.
2.1. nxn (n<=10), . , . .
2.2. nxn (n<=10), . , 3, , . .
2.3. nxn (n<=10), . , . .
2.4. nxn (n<=10), . , . , , , . .
2.5. n (n<=20), . , .
2.6. nxn (n<=10), . , , . .
2.7. nxn (n<=10), . , . , , , . .
2.8. n nxn (n<=10), . . .
2.9. n (n<=20), . , . , .
2.10. nxn (n<=10), . , , .
3. Ͳ
3.1. .
3.2. .
3.3. .
3.4. .
14
, Ͳ , Ѳ ² "Ѳ"
"Ѳ" , , .
1. Ͳ ²Ҳ
1.1. "Ѳ" "". struct, , , ,
struct { 1 1;
2 2;
...............................
n n;};
- . , ,
struct date{int day;
int month;
int year;};
, ,
struct date{} a,b,c;
ᒺ . , . , ,
date a;
, . , ,
struct pupil{char name[15],
firstname[15];
struct date borndate;
int class, age;};
ϳ date pupil , , ,
struct pupil pupils[50];