Главная »
2017 » Март » 17 » строка. сумма двух чисел в строке
12:54 строка. сумма двух чисел в строке |
#include<iostream>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
char st1[80];
cout<<"Vvedite stroku"<<endl;
gets(st1);
int s1=0;
int i=0;
while (st1[i]!='+')
{
if ((st1[i]>='0')&&(st1[i]<='9'))
{
int a=(int)st1[i]-(int)'0';
s1=s1*10+a;
}
i++;
}
i++;
int s2=0;
while (st1[i])
{
if ((st1[i]>='0')&&(st1[i]<='9'))
{
int a=(int)st1[i]-(int)'0';
s2=s2*10+a;
}
i++;
}
cout <<"Число1="<<s1<<endl;
cout <<"Число2="<<s2<<endl;
cout <<"Summa="<<s1+s2<<endl;
system("pause");
return 0;
}
|
Просмотров: 448 |
Добавил: denjes
| Рейтинг: 0.0/0 |