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

Void main(void)

{clrscr();

int Numbers[] = {0,3,50,45,2,8};

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

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

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

char *inttostr(int chislo)

{ char *s="000000";

int n,pos=5;

while (chislo > 0){

n = chislo % 2;

chislo /=2;

if (n==0) s[pos--]='0';

else s[pos--]='1';}

while (pos>-1)

s[pos--]='0';

return s;}

int strtoint(char *s)

{int sum=0;

while (*s)

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

return (sum);}

//10-'8'-10

#include <stdio.h>

#include <conio.h>

char *inttostr(int chislo);

int strtoint(char *s);

Void main(void)

{clrscr();

int Numbers[] = {10,3,50,190,9,8};

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

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

inttostr(Numbers[i]), strtoint(inttostr(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();

int Numbers[] = {0,23,50,100,9,8};

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

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

inttostr(Numbers[i]), strtoint(inttostr(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);}

//10-'16'-10

#include <stdio.h>

#include <conio.h>

char *inttostr(int chislo);

int strtoint(char *s);

Void main(void)

{clrscr();

int Numbers[] = {0,3,50,45,28,8};

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

printf("\n int %d, \t String %s, \t int %d", Numbers[i], inttostr(Numbers[i]), strtoint(inttostr(Numbers[i])));}

char *inttostr(int 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;}

Int strtoint(char *s)

{int sum=0;

while (*s)

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

return (sum);}

//'2'-10-'2'

#include <stdio.h>

#include <conio.h>

char *inttostr(int chislo);

Int strtoint(char *s);

Void main(void)

{clrscr();

char *Numbers[] = {"000","11001","101","1010","1111","110"};

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 % 2;

chislo /=2;

if (n==0) s[pos--]='0';

else s[pos--]='1';}

while (pos>-1)

s[pos--]='0';

return s;}

Int strtoint(char *s)

{int sum=0;

while (*s)

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

return (sum);}

//'8'-10-'8'

#include <stdio.h>

#include <conio.h>

char *inttostr(int chislo);