Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <cstring>
  5. #include <cctype>
  6. #include "stdlib.h"
  7. #include <ctype.h>
  8. using namespace std;
  9. void task1() {
  10.     char s[1000];  // создаём массивы символов
  11.     int s1[1000];
  12.     cout << "Введите текст: ";
  13.     fgets(s, sizeof(s), stdin);  //ввод с клавиатуры в массив
  14.     int i = 0, c = 0;
  15.     while (s[i] != '\n')
  16.     {
  17.         if (isdigit(s[i])) {
  18.             s1[i] = int(s[i]) - 48;    //перевод из char в int и запись в новый массив
  19.             c++;
  20.             i++;
  21.         }
  22.         else{
  23.             cout << "Номер символа который нельзя преобразовать в число: " << i+1  << endl;
  24.             c = 0;
  25.             break;
  26.             }
  27.     }
  28.     if (c != 0) {  
  29.         int number = 0;             //перевод массива цифр в 1 число
  30.         for (int i = 0; i < c; i++) {
  31.             number *= 10;
  32.             number += s1[i];
  33.         }
  34.         cout << number << endl;   //вывод итогового числа
  35.     }
  36.    
  37.    
  38.    
  39. }
  40.     int main()
  41. {
  42.     setlocale(LC_ALL, "Russian");
  43.     task1();
  44.     system("pause");
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement