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

Void main(void)

{ clrscr();

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

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','8','9'};

drob=chislo;

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

cel=drob*10;

drob=drob*10-cel;

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

while (pos<8)

s[pos++]='0';

return s;}

float strtoflo(char *s)

{float d=0, p=0.1;

s+=2;

while (*s){

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

p*=0.1;}

return d;}

//dr 10-'10'-10

#include <stdio.h>

#include <conio.h>

char *flotostr(float chislo);

float strtoflo(char *s);

Void main(void)

{clrscr();

float Numbers[] = {0.001,0.23,0.50,0.111,0.000,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*10;

drob=drob*10-cel;

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

while (pos<8)

s[pos++]='0';

return s;}

float strtoflo(char *s)

{float d=0, p=0.1;

s+=2;

while (*s){

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

p*=0.1;}

return d;}

//dr 10-'16'-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', 'A','B','C','D','E','F'};

drob=chislo;

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

cel=drob*16;

drob=drob*16-cel;

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

while (pos<8)

s[pos++]='0';

return s;}

float strtoflo(char *s)

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

while (*s){

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

p*=0.0625;}

return d;}

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

#include <stdio.h>

#include <conio.h>

char *flotostr(float chislo);

float strtoflo(char *s);

Void main(void)

{ clrscr();

char *Numbers[] = {"0.000","0.A","0.1","0.F","0.ABC","0.1F2D"};

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','8','9',

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

drob=chislo;

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

cel=drob*16;

drob=drob*16-cel;

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

while (pos<8)

s[pos++]='0';

return s;}

float strtoflo(char *s)

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

while (*s){

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

p*=0.0625;}

return d;}

//10-'2'-10

#include <stdio.h>

#include <conio.h>

char *inttostr(int chislo);

int strtoint(char *s);