I have to input 2 numbers, n and k, and find the product of n's digits which are different from k. Example: n = 1234, k=2, and the product should be 1 * 3 * 4;
#include <iostream>
using namespace std;
int main()
{
int n, k, p=1, digit;
cin >> n >> k;
while(true){
digit= n % 10;
if(digit != k){
p = p * digit;
}
n = n/10;
}
cout << "Product of digits different from K is: " << p;
return 0;
}
When i run it, after i input n and k, the program doesnt do anything else and just keeps the console open without an output.