Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ЭКЗАМЕН_ПРОГ.doc
Скачиваний:
23
Добавлен:
23.09.2019
Размер:
50.18 Кб
Скачать

Int strtoint(char *s);

Void main(void)

{clrscr();

char *Numbers[] = {"000","123","777","101","535","10"};

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

printf("\n String %s, \t int %d, \t String %s", Numbers[i],

strtoint(Numbers[i]), inttostr(strtoint(Numbers[i])));}

char *inttostr(int chislo)

{ char *s="000000";

int n,pos=5;

while (chislo > 0){

n = chislo % 8;

chislo /=8;

s[pos--]='0'+n;}

while (pos>-1)

s[pos--]='0';

return s;}

Int strtoint(char *s)

{int sum=0;

while (*s)

sum= sum*8+(*s++ -'0');

return (sum);}

//'10'-10-'10'

#include <stdio.h>

#include <conio.h>

char *inttostr(int chislo);

Int strtoint(char *s);

Void main(void)

{clrscr();

char *Numbers[] = {"000","123","777","1000","535","10"};

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

printf("\n String %s, \t int %d, \t String %s", Numbers[i],

strtoint(Numbers[i]), inttostr(strtoint(Numbers[i])));}

char *inttostr(int chislo)

{ char *s="000000";

int n,pos=5;

while (chislo > 0){

n = chislo % 10;

chislo /=10;

s[pos--]='0'+n;}

while (pos>-1)

s[pos--]='0';

return s;}

Int strtoint(char *s)

{int sum=0;

while (*s)

sum= sum*10+(*s++ -'0');

return (sum);}

//'16'-10-'16'

#include <stdio.h>

#include <conio.h>

char *inttostr(long chislo);

long strtoint(char *s);

Void main(void)

{clrscr();

char *Numbers[] = {"000","1AA","FFFFF","FFFF","1E","10"};

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

printf("\n String %s, \t int %ld, \t String %s", Numbers[i],

strtoint(Numbers[i]), inttostr(strtoint(Numbers[i])));}

char *inttostr(long chislo)

{ char *s="000000";

int n,pos=5;

char mas[]={'0','1','2','3','4','5','6','7','8','9',

'A','B','C','D','E','F'};

while (chislo > 0){

n = chislo % 16;

chislo /=16;

s[pos--]=mas[n];}

while (pos>-1)

s[pos--]='0';

return s;}

long strtoint(char *s)

{long sum=0;

while (*s)

sum= sum*16+(*s>'9'?(*s++ -'A'+10):(*s++ -'0'));

return (sum);}