jeudi 21 avril 2016

Why iterate each digit in a number and find evenly divided digits not working?

I am writing a code in which a input is taken to run some no of test case and in each test case we have to iterate the number through each number and we have to divide it with the initial number taken and if it gives remainder 0 then we need to increment the count otherwise we need not increment the count and at last we will print the count.


The number 12 is broken into two digits, 1 and 2. When 12 is divided by either of those digits, the calculation's remainder is 0; thus, the number of evenly-divisible digits in 12 is 2

Compiler Message

Floating Point Exception

The code is given below and when running in a c compiler the program abruptly stops after taking the input.

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
    int t; 
    int n[t],b,rem;
        int count =0;
    scanf("%d",&t);
    for(int a0 = 0; a0 < t; a0++){

        scanf("%d",&n[a0]);
    }
    for(int i=0;i<t;i++){
        b =n[i];
        while (n[i]) {
            rem = n[i] % 10;
            if(b%rem == 0)
                count++;

             n[i] = n[i] / 10;

         }
        printf("%d\n",count);
    }
    return 0;
}

.

Aucun commentaire:

Enregistrer un commentaire