Главная » 2019 » Март » 12 » Строки. StrToInt, StrToDouble
09:20
Строки. StrToInt, StrToDouble

#include <iostream>
using namespace std;
void vvod(char *x);
void vivod(char *x);
int StrToInt(char *x);
double StrToDouble(char *x);
int main()
{
    const int n=200;
    char str[n];
    cout<<"Vvedite stroku: "; vvod(str);
    cout<<"a= "<<StrToDouble(str)<<endl;
    system("pause");
}
double StrToDouble(char *x)
{
    int c,i,p=1;
    double a=0;
    for (i=0;x[i]!='.';i++)
        a=a*10+(int)x[i]-(int)'0';
    for (i=i+1;i<strlen(x);i++,p*=10)
        a=a*10+(int)x[i]-(int)'0';
    return a/p;
}
int StrToInt(char *x)
{
    int a=0,c;
    for (int i=0;i<strlen(x);i++)
    {
        c=(int)x[i]-(int)'0';
        a=a*10+c;
    }
    return a;
}
void vvod(char *x)
{
    gets(x);
}
void vivod(char *x)
{
    cout<<x<<endl;
}

Просмотров: 323 | Добавил: denjes | Рейтинг: 0.0/0
Всего комментариев: 0
avatar