.


:




:

































 

 

 

 





² C

 

, Ѳ.

 

1. Ͳ ²Ҳ

 

1.1. , , ᒺ FILE. , ,

 

FILE *lst;

 

FILE - , stdio.h; lst ;

³ fopen, :

 

FILE *fopen ( , );

 

fopen , NULL, . Գ , .

:

w - ; , ;

r - ;

a - , .

+, , , :

 

FILE *lst;

lst=fopen(D:\TC\file.txt,r+);

D:\TC\file.txt , .

fflush, . :

 

int fflush (__);

 

EOF , 0 .

ϳ fclose, :

 

int fclose(__);

 

remove. :

 

int remove(_);

remove, :

int rename(__, __);

 

remove, rename 0, .

 

1.2. - fprint fscanf , :

 

int fprintf (__, , );

int fscanf (__, , );

 

ᒺ :

- , ;

- , ;

- ( , , .).

% , . ̳ :

- - , , . - ;

- , . , , float double;

- l, long;

():

d - ;

o - ;

x - ;

c - ( char);

s - (string);

e - ;

f - (float);

g - e f, ;

u - (unsigned);

p - (pointer).

% , .

:

\a - (alarm);

\b - (back);

\n - (new);

\r - ( ) (return);

\t - (tabulation);

\v - (vertical).

 

1. ³ . 10 10 .

 

#include <stdio.h>

main()

{int i,j;

FILE *lds;

lds=fopen("epa.txt","w");

/*³ . , */

for(i=1;i<=10;i++)

for(j=1;j<=10;j++)

fprintf(lds,"%d%c",i+j-1,((j==10)?'\n':' '));

/* */

/* , printf*/

fprintf(lds,"\n");

fclose(lds);

/* */

}

 

1.3. fgetc fputc , :

 

int fgetc(__);

int fputc(__);

fgetc , , EOF . fputs , , , EOF .

- fgets fputs, , fgetc, fputc.

 

1.4. - fwrite fread . :

 

int fread (__, _ᒺ, _ᒺ, __); ᒺ , __, ᒺ _ᒺ, _ᒺ , __. ᒺ. int fwrite(__, _ᒺ, _ᒺ, __); ᒺ , __, ᒺ _ᒺ, _ᒺ , __. ᒺ. 1.5. . fseek, : int fseek(_, , . );

. , . :

SEEK_SET ;

SEEK_CUR ;

SEEK_END ;

ftell , :

 

long ftell(__);

 

2. .

 

#include <stdio.h>

#include <conio.h>

void main(void)

{

const n=10;

int a[10];

FILE *pfile;

int i,j,pos,start;

int *pstart;

pstart=&start;

/* start */

clrscr();

printf("\nFilling vector with numbers...\n\n a=[ ");

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

{

a[i]=i+1;

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

}

printf("]\n\nCreating binary file epa.dat for editing...");

pfile=fopen("epa.dat","w+b");

/* */

j=fwrite(a,sizeof(int),n,pfile);

/* */

if(j<n) printf("\n\nAn error occured. Only %d of %d elements was written",j,n);

else printf("\n\nFile was filled with %d elements successfully",j);

fflush(pfile);

/* */

printf("\n\nEnter the number of element you want to read from bin file ");

scanf("%d",&j);

fseek(pfile,(j-1)*sizeof(int),SEEK_SET);

/* */

pos=ftell(pfile);

/* */

fread(pstart,sizeof(int),1,pfile);

printf("\n\nSEEK_SET: %dth element position is %d, element is %d",j,pos,*pstart);

printf("\n\nPress any key to exit");

getch();

fclose(pfile); /* */

}

 

2.

 

"Ѳ", .

2.1. ³ , ' . , . .

2.2. privod.dat, (n<=30). , . .

2.3. ³ , . . , .

2.4. Y=A*sin(B*X) X 0 2 0.01. . temp.txt 2 . , . result.txt.

2.5. Y=+A*sin(B*X+D) X 1 3 0.1. , B, C, D . , . .

2.6. epa.txt, 1010. .

2.7. , ' . .

2.8. , , . 3 , ' . , , .

2.9. , ֳ, . 4 , ' . , , .

2.10. , . (n<=20). 5 , . . .

 

3. Ͳ

 

3.1. - .

3.2. .

3.3. .

3.4. .

3.5. .

3.6. -.


16

ֲ ² Ѳ

 

- Ѳ.

 

1. Ͳ ²Ҳ

 

1.1. , , . . .

 

_ _(1 1,..., _n _n);

 

, f, , a b, :

 

int f(int a, int b);

ҳ , {}. ҳ return, ,

 

return <>;

 

1. . .

 

#include <stdio.h>

#include <string.h>

/* strlen - */

int revers(char s[50]);

/* revers - */

{int i,j,c;

for(i=0, j=strlen(s)-1; i<j; i++, j--)

{c=s[i]; s[i]=s[j]; s[j]=c;}

return(0);}

int cc(char s[], char sn[]);

/* - */

{int i,k=0;

for(i=0;i<strlen(s);i++)

{if (s[i]>='0'&&s[i]<='9')

sn[k++]=s[i];}

sn[k]='\0';

return(0);

}

main()

{char s[50],sn[50];

puts("\n\nInput string");

/* */

do {scanf("%s",s);

revers(s);

printf("\n%s\n",s);}

while(s[0]=='0');

/* 0 */

cc(s,sn);

printf("\nNumerical symbols in the string are- %s",sn);

}

 

2. . .

 

#include <stdio.h>

void display(int num[10]);

{

int i;

for(i=0;i<10;i++) printf("%d",num[i]);

}

int main(void)

{int t[10], i;

for(i=0;i<10;i++) t[i]=i;

display(t);

return 0;

}

 

, ﳿ . , , .

3. , .

 

#include <stdio.h>

void swap(int *a, int *b)

{

int temp;

temp=*a;

*a=*b;

*b=temp;

};

void main(void)

{

int num1, num2;

printf("\n\nEnter two integers ");

scanf("%d %d",&num1,&num2);

swap(&num1,&num2);

printf("Swapped integers are %d %d",num1,num2);

getch();

}

 

:

 

void display(int num[])

{int i;

for(i=0;i<10;i++) printf("%d",num[i]);

}

 

num . , .

:

 

void display(int *num)

{int i;

for(i=0;i<10;i++) printf("%d",num[i]);

}

 

main() , . , 0.

 

1.2. . , . .

4. n!, .

 

#include <stdio.h>

int factr(int n)

/* */

{int answer;

if (n==1) return 1;

answer=factr(n-1)*n;

return answer;

}

main()

{

int k=5;

printf("\nn!=%d",factr(k));

}

 

1.3. CI :

 

int main(int argc, char *argv)

 

argc , *argv - . , argv[0] , argc>=1. , :

 

argv[argc]=NULL

 

TURBO C Run/Arguments.

5. , . .

 

#include <stdio.h>

#include <conio.h>

int numspace(char *fname)

{

FILE *pfile;

int c,cnt=0;

pfile=fopen(fname,"r");

while((c=getc(pfile))!=EOF)

if(c==' ')cnt++;

close(pfile);

return cnt;

}

void main(int argc, char *argv[])

{

int i;

clrscr();

for(i=1;i<argc;i++)

{

printf("Number of spaces in file %s is %d\n\n",argv[i],numspace(argv[i]));

}

getch();

}

 

6. , argv .

 

#include <stdio.h>

#include <conio.h>

int numspace(char *fname)

{

FILE *pfile;

int c,cnt=0;

pfile=fopen(fname,"r");

while((c=getc(pfile))!=EOF)

if(c==' ')cnt++;

close(pfile);

return cnt;

}

void main(int argc, char *argv[])

{

clrscr();

while(argc-->1)

{

argv++;

printf("Number of spaces in file %s is %d\n\n",*argv,numspace(*argv));

}

getch();

}

 

2.

 

Ѳ, .

2.1. n Գ F0=F1=0, Fn+2=Fn+1+Fn, n<=10. . .

2.2. AX2+BX+C=0. , B, C .

2.3. , . .

2.4. , . .

2.5. , . .

2.6. , , AX+BY+C=0 . . , B, C .

2.7. . .

2.8. , , B (xb;yb) A (xa;ya) C(xc;yc). .

2.9. , , D (xd;yd) A (xa;ya), B (xb;yb) C(xc;yc). .

2.10. , , AX+BY+C=0 A1X+B1Y+C1=0. . , .

 

3. Ͳ

 





:


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


:

:

, ,
==> ...

1299 - | 1282 -


© 2015-2024 lektsii.org - -

: 0.159 .