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

//dr '2'-10-'2'

#include <stdio.h>

#include <conio.h>

char *flotostr(float chislo);

float strtoflo(char *s);

Void main(void)

{ clrscr();

char *Numbers[] = {"0.000","0.1","0.110001","0.111","0.101","0.0001"};

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

printf(" \n String %8s, \t float %10.6f, \t string %8s", Numbers[i],strtoflo(Numbers[i]), flotostr(strtoflo(Numbers[i]))); }

char *flotostr(float chislo)

{char *s="0.000000";

int cel, pos=2;

float drob;

const char all[]={'0','1'};

drob=chislo;

while ((pos!=8)&&(drob!=0)){

cel=drob*2;

drob=drob*2-cel;

s[pos++]=all[cel];}

while (pos<8)

s[pos++]='0';

return s; }

float strtoflo(char *s)

{float d=0, p=0.5; s+=2;

while (*s)

{d+=(*s++ -'0')*p;

p*=0.5;}

return d; }

//dr 10-'2'-10

#include <stdio.h>

#include <conio.h>

char *flotostr(float chislo);

float strtoflo(char *s);

Void main(void)

{clrscr();

float Numbers[] = {0.001,0.5378,0.50,0.111,0.7689,0.999};

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

printf("\n float %10.6f, \t String %8s, \t float %10.6f", Numbers[i], flotostr(Numbers[i]), strtoflo(flotostr(Numbers[i]))); }

char *flotostr(float chislo)

{char *s="0.000000";

int cel, pos=2;

float drob;

const char all[]={'0','1'};//,'2','3','4','5','6','7','8','9'};

drob=chislo;

while ((pos!=8)&&(drob!=0)){

cel=drob*2;

drob=drob*2-cel;

s[pos++]=all[cel];}

while (pos<8)

s[pos++]='0';

return s;}

float strtoflo(char *s)

{float d=0, p=0.5;

s+=2;

while (*s){

d+=(*s++ -'0')*p;

p*=0.5;}

return d; }

//dr '8'-10-'8'

#include <stdio.h>

#include <conio.h>

char *flotostr(float chislo);

float strtoflo(char *s);

Void main(void)

{clrscr();

char *Numbers[]= {"0.000","0.777","0.0055","0.111","0.4","0.0001"};

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

printf(" \n String %8s, \t float %10.6f, \t string %8s", Numbers[i], strtoflo(Numbers[i]), flotostr(strtoflo(Numbers[i]))); }

char *flotostr(float chislo)

{char *s="0.000000";

int cel, pos=2;

float drob;

const char all[]={'0','1','2','3','4','5','6','7'};

drob=chislo;

while ((pos!=8)&&(drob!=0)){

cel=drob*8;

drob=drob*8-cel;

s[pos++]=all[cel];}

while (pos<8)

s[pos++]='0';

return s; }

float strtoflo(char *s)

{float d=0, p=0.125;

s+=2;

while (*s){

d+=(*s++ -'0')*p;

p*=0.125;}

return d;}

//dr 10-'8'-10

#include <stdio.h>

#include <conio.h>

char *flotostr(float chislo);

float strtoflo(char *s);

Void main(void)

{clrscr();

float Numbers[] = {0.001,0.5378,0.50,0.111,0.7689,0.999};

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

printf("\n float %10.6f, \t String %8s, \t float %10.6f", Numbers[i], flotostr(Numbers[i]), strtoflo(flotostr(Numbers[i])));}

char *flotostr(float chislo)

{char *s="0.000000";

int cel, pos=2;

float drob;

const char all[]={'0','1','2','3','4','5','6','7'};

drob=chislo;

while ((pos!=8)&&(drob!=0)){

cel=drob*8;

drob=drob*8-cel;

s[pos++]=all[cel];}

while (pos<8)

s[pos++]='0';

return s;}

float strtoflo(char *s)

{float d=0, p=0.125; s+=2;

while (*s)

{d+=(*s++ -'0')*p;

p*=0.125;}

return d;}

//dr '10'-10-'10'

#include <stdio.h>

#include <conio.h>

char *flotostr(float chislo);

float strtoflo(char *s);