C语言while语句问题
输入两个整数,判定第二个数是否是第一个数的约数,但是,不能用%,要用while语句,运算结果为Input first number:120
Input second number:4
4 is a divisor of 120.
或
Input first number:55
Input second number:6
6 is not a divisor of 55.
我是想在while语句中用if语句来做,但怎么做都不太对,求指教!!
#include <stdio.h> int main(void) { int a, b, i = 1; printf("Input first number:"); scanf("%d", &a); printf("Input second number:"); scanf("%d", &b); while(i <= a) { if(b * i == a) { printf("%d is a divisor of %d.\n", b, a); break; } i++; } if(i > a) printf("%d is not a divisor of %d.\n", b, a); }