Answer to Question #231709 in C++ for knight_manakal

Question #231709

Write statements to validate the number given below is a 4-digit integer and then to print the digits divisible by 2.


1
Expert's answer
2021-08-31T23:51:33-0400
//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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS