1)Напишите программу, которая определяет, верно ли, что введенное число состоит из одинаковых цифр(например, 222)
2)Напишите программу, которая определяет, верно ли, что введеное число содержит две одинаковые цифры, стоящие рядом (например, 221)
Паскаль
Ответы
Ответ дал:
0
1)
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int a;
cin >> a;
int d = a%10;
string s = "yes";
while(abs(a) > 0) {
if(a%10 != d) {
s = "no";
break;
}
a/=10;
}
cout << s << endl;
}
2)
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int a;
cin >> a;
int d = a%10;
a/=10;
string s = "no";
while(abs(a) > 0) {
if(a%10 == d) {
s = "yes";
break;
}
d = a%10;
a/=10;
}
cout << s << endl;
}
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int a;
cin >> a;
int d = a%10;
string s = "yes";
while(abs(a) > 0) {
if(a%10 != d) {
s = "no";
break;
}
a/=10;
}
cout << s << endl;
}
2)
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int a;
cin >> a;
int d = a%10;
a/=10;
string s = "no";
while(abs(a) > 0) {
if(a%10 == d) {
s = "yes";
break;
}
d = a%10;
a/=10;
}
cout << s << endl;
}
Похожие вопросы
2 года назад
2 года назад
6 лет назад
6 лет назад
9 лет назад
9 лет назад
9 лет назад