Write statements to validate the number given below is a 4-digit integer and then to print the digits divisible by 2.
//corecudr
#include <bits/stdc++.h>
using namespace std;
void isDivisible(long long int n)
{
long long int temp = n;
int dig = 0;
while (n) {
n /= 10;
dig++;
}
if (dig == 4) {
while (temp) {
int k = temp % 10;
if (k%2==0) cout << k << '\n';
temp /= 10;
}
} else cout << "No\n";
}
int main()
{
long long int n = 1234;
isDivisible(n);
return 0;
}
Input 1:
1234
Output 1:
4
2
Comments
Leave a comment