mercredi 1 février 2023

I was doing a code for , "Count Digits " , Evenly divides means whether N is divisible by a digit i.e. leaves a remainder 0 when divided

#include<bits/stdc++.h>
using namespace std; 

int main() {


int n,m,z;
   cout<<"enter n: ";
   cin>>n;
     z=n;

    int count=0;
while(n>0){
    m = n % 10;
    if(z%m == 0){
        count++;
    }
    n=n/10;
}
cout<<count;

}

Code should work like that ex - for n = 12, it is divisible by both 1 , 2 so, the output will be 2 if i am taking any value which have '0' in their last then it is not working ..and i am getting an error "Floating-point exception (SIGFPE)". Could anyone help me to get rid out of this.

Aucun commentaire:

Enregistrer un commentaire