Advertisement
CosminVarlan

Untitled

Oct 19th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6.  
  7.  
  8.  
  9. int main()
  10. {
  11.  
  12.      char a[11];
  13.      cin.get(a,11);
  14.  
  15.      int bv=0;  // beforeVirgula
  16.      int av=0;  // afterVirgula
  17.  
  18.      if (strchr(a,'.'))
  19.      {
  20.          while (a[strlen(a)-1]=='0') a[strlen(a)-1]=0;
  21.      }
  22.  
  23.      int gasitVirgula=0;
  24.      for(int i=0; i<strlen(a); i++)
  25.      {
  26.         if (a[i]=='.')
  27.         {
  28.             gasitVirgula=1;
  29.             i++;
  30.         }
  31.         if (gasitVirgula==0)
  32.         {
  33.             bv = bv * 10 + (a[i]-'0');
  34.         }
  35.         else
  36.         {
  37.             av = av * 10 + (a[i]-'0');
  38.         }
  39.      }
  40.      cout << av+bv;
  41.  
  42.  
  43.  
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement