Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

พิมพ์เลขคูณของหลักหน่วยของตัวเลขที่กำหนด ในภาษา C

รับตัวเลข N หาหลักหน่วย (N % 10) แล้วหาเลขคูณของหลักหน่วยนั้น (ยกเว้น 1 และตัวมันเอง)

ตัวอย่าง

Input: 326 → หลักหน่วย = 6 → เลขคูณ: 2, 3

โค้ดตัวอย่าง

#include <stdio.h>

int main() {
    int num, unit, i;
    printf("Enter a number: ");
    scanf("%d", &num);
    unit = num % 10;
    printf("Unit digit of %d is: %d\n", num, unit);
    for (i = 2; i <= unit / 2; ++i) {
        if (unit % i == 0)
            printf("Multiple of %d is: %d\n", unit, i);
    }
    return 0;
}

ผลลัพธ์

enter a number 329
unit digit of 329 is: 9
multiple of 9 is: 3