Advertisement
Courbe_Impliquee

Сумма цифр в строке

Apr 8th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. # include <stdio.h>
  2. # include <conio.h>
  3. # include <iostream>
  4. # include "stdafx.h"
  5. using namespace std;
  6. int main()
  7. {
  8. char str[80];
  9. int sum = 0,i=0;
  10. gets(str);
  11. while (str[i] && str[i] != '\n')
  12. {
  13. if (str[i] >= '0' && str[i] <= '9')
  14. sum += str[i] - '0';
  15. i++;
  16. }
  17. cout << "Sum =" << sum;
  18. system("pause");
  19. return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement