Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma hdrstop
- #pragma argsused
- #ifdef _WIN32
- #include <tchar.h>
- #else
- typedef char _TCHAR;
- #define _tmain main
- #endif
- #include <stdio.h>
- #include <iostream>
- #include <conio.h>
- #include <math.h>
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- float b;
- cin >>b;
- cout << "b : "<<b<< endl;
- char str[51]={'\0'};
- float c = 1.4013e-45;
- if (b<c) {
- str[0]='0';
- cout <<"str : "<< str;
- getch();
- return 0;
- }
- if (b==10) {
- str[0]='1';
- str[1]='0';
- cout <<"str : "<< str;
- getch();
- return 0;
- }
- if (b==1) {
- str[0]='1';
- cout <<"str : "<< str;
- getch();
- return 0;
- }
- //cout << "c : "<<c<< endl;
- //cout << "str : "<<str<< endl;
- float f = b;
- int i=0;
- if ((f>10)||(f<1)) do
- {
- i++;
- f= b>1?f/10:f*10;
- //cout << "f "<<i<<" : "<<f<< endl;
- }while ((f>=10)||(f<1)) ;
- f += 5.1e-6;
- if(f>=10){ i--; f/=10; }
- //cout << "i "<<i<< endl;
- str[0]=char((int)f%10+'0');
- cout << "str[0] " <<str[0]<< endl;
- str[1]='.';
- for (int j= 2; j < 7; j++) {
- f*=10;
- //str[j]=char((int)f%10+'0');
- //cout << "str["<<j<<"] : "<<str[j]<< endl;
- }
- int x=(int) round(f);
- cout << "x : "<<x<< endl;
- for (int j = 6; j>1; j--) {
- str[j]=char(x%10+'0'); cout << "str["<<j<<"] : "<<str[j]<< endl;
- x/=10;
- //cout << "x : "<<x<< endl;
- }
- /*int j;
- for (j= 6; j >1; j--)
- {
- if (str[j]=='0') {
- str[j]='\0';
- }
- else break;
- }
- if (j==1)
- {
- str[1]='\0';
- j--;
- }
- if (i>=6)
- {
- str[j+1]='e';
- if (b>1) {
- str[j+2]='+';
- }
- else str[j+2]='-';
- str[j+3]=char(i/10+'0');
- str[j+4]=char(i%10+'0');
- }
- */
- int pofe = 0;
- int point = 0;
- if (i<6) {
- if (b>1) {
- for (int h = 2; h <=i+1; h++) {
- str[h-1]=str[h]; cout << "str[" << h-1 << "] : " << str[h-1] << endl;
- }
- str[i+1]='.'; point = i+1;
- pofe=6;
- }
- else {
- str[1]=str[0];
- for (int h = 6; h >0; h--)
- {
- str[h+i]=str[h];
- }
- str[0]='0';
- str[1]='.'; point = 1;
- for (int h = 2; h < 1+i; h++)
- {
- str[h]='0';
- }
- pofe=6+i;
- }
- }
- else {
- pofe=6; point = 1;
- /* str[7]='e';
- if (b>1) {
- str[8]='+';
- }
- else str[j+2]='-';
- str[9]=char(i/10+'0');
- str[10]=char(i%10+'0'); */
- }
- int j;
- for (j= pofe; j >point; j--)
- {
- if (str[j]=='0') {
- str[j]='\0';
- }
- else break;
- }
- if (j==point)
- {
- str[point]='\0';
- j--;
- }
- if (i>=6)
- {
- str[j+1]='e';
- if (b>1) {
- str[j+2]='+';
- }
- else str[j+2]='-';
- str[j+3]=char(i/10+'0');
- str[j+4]=char(i%10+'0');
- }
- cout << "str " <<str<< endl;
- //cout << "f : "<<f<< endl;
- getch();
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment