Answer to Question #279951 in C for Jooooba

Question #279951

Please program to output all integers between 0 and 200 that are divisible by 3 and whose single digit is 6.


1
Expert's answer
2021-12-15T16:23:31-0500
#include <stdio.h>

int hasSinglDigit(int x, int d) {
    int has=0;


    if (x == 0 && d == 0)
        return 1;
    
    while (x>0) {
        if (x%10 == d) {
            if (has) {
                return 0;
            }
            has = 1;
        }
        x /= 10;
    }
    return has;
}

int main() {
    int n=0;

    for (int i=0; i<=200; i++) {
        if (i%3 == 0 && hasSinglDigit(i, 6)) {
            if (n == 0) {
                printf("%d", i);
            }
            else {
                printf(", %d", i);
            }
            n++;
        }
    }
    printf("\n");

    return 0;
}

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