Сделать программу, которая проверяет, является ли введенная с клавиатуры строка двоичным числом.
Решение:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include “stdafx.h” #include <iostream> using namespace std; int main() {setlocale(LC_ALL,“Rus”); char stroka[255]; int _int, i=0, n, x=0; cout<<” Введите строку >> \t \n“; cin.getline(stroka, 255); n=strlen(stroka); while (i<n) { _int=stroka[i]; if ((_int==44) || (_int==46) || (_int==48) || (_int==49)) x++; i++; } if (x!=i) cout<<stroka<<” – не двоичное число “; else cout<<stroka<<” – двоичное число “; system(“pause>>void”); return 0; } |
