Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <stdio.h>
- #include <cstring>
- #include <cctype>
- #include "stdlib.h"
- #include <ctype.h>
- using namespace std;
- void task1() {
- char s[1000]; // создаём массивы символов
- int s1[1000];
- cout << "Введите текст: ";
- fgets(s, sizeof(s), stdin); //ввод с клавиатуры в массив
- int i = 0, c = 0;
- while (s[i] != '\n')
- {
- if (isdigit(s[i])) {
- s1[i] = int(s[i]) - 48; //перевод из char в int и запись в новый массив
- c++;
- i++;
- }
- else{
- cout << "Номер символа который нельзя преобразовать в число: " << i+1 << endl;
- c = 0;
- break;
- }
- }
- if (c != 0) {
- int number = 0; //перевод массива цифр в 1 число
- for (int i = 0; i < c; i++) {
- number *= 10;
- number += s1[i];
- }
- cout << number << endl; //вывод итогового числа
- }
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- task1();
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement