Advertisement
Alberts00

cpp uzd 12.03.2013

Mar 19th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. long skaitlisrinda(string a){
  7.     long l = 0;
  8.     int i = 0;
  9.     while( (a[i] < '0' || a[i] > '9') && a[i] ) i++;
  10.     while( a[i] >= '0' && a[i] <= '9') {
  11.       l = ((l*10) + (long)(a[i] - '0')); i++;
  12.     }
  13.     return( l );
  14. }
  15.      
  16.  
  17. int main(int argc, char *argv[]) {
  18.     string a1, a2;
  19.     long l1,l2;
  20.     cout << "Ievadiet pirmo rindu:\n";
  21.     cin >> a1;
  22.     cout << "Ievadiet otro rindu:\n";
  23.     cin >> a2;
  24.     l1 = skaitlisrinda(a1);
  25.     l2 = skaitlisrinda(a2);
  26.     cout << "\nSumma = " << l1 << "+" << l2 << "=" << (l1 + l2)<< endl;
  27.    
  28.     system("pause");
  29.     return 0;
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement