Advertisement
Nita_Cristian

Problema -6

Nov 19th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. /// Se da un text format din litere cifre si spatii sa se calculeze suma cifrelor din text
  2. #include<iostream>
  3. #include<cstring>
  4.  
  5. using namespace std;
  6.  
  7. char x[256];
  8.  
  9. int main()
  10. {
  11.     int s = 0;
  12.  
  13.     cin.getline(x,256);
  14.  
  15.     for(int i = 0; i < strlen(x); i++)
  16.     {
  17.         if(isalnum(x[i]) && !isalpha(x[i]))
  18.         {
  19.             s += x[i] - '0';
  20.         }
  21.     }
  22.     cout << s;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement