Главная » 2017 » Март » 17 » строка. подсчитать сумму всех цифр
12:00
строка. подсчитать сумму всех цифр

#include<iostream>
using namespace std;
int main()
{
    setlocale(LC_ALL, "Russian");
    char st[80];
    gets(st);
    int s=0;
    int i=0;
    while (st[i])
    {
        if ((st[i]>='0')&&(st[i]<='9'))
        {
            int a=(int)st[i]-(int)'0';
            s=s+a;
        }
        i++;
    }
    cout <<"Summa="<<s<<endl;
    system("pause");
    return 0;
}

Просмотров: 324 | Добавил: denjes | Рейтинг: 0.0/0
Всего комментариев: 0
avatar