小智 14
void main(){
int a,b,i=0;
clrscr();
printf("Enter the dividend and divisor");
scanf("%d%d",&a,&b);
while(a>=b){
a=a-b;
i++;
}
printf("qoutient is :%d \n remainder : %d",i,a);
getch();
}
Run Code Online (Sandbox Code Playgroud)
您可以使用此功能
int divide(int nu, int de) {
int temp = 1;
int quotient = 0;
while (de <= nu) {
de <<= 1;
temp <<= 1;
}
//printf("%d %d\n",de,temp,nu);
while (temp > 1) {
de >>= 1;
temp >>= 1;
if (nu >= de) {
nu -= de;
//printf("%d %d\n",quotient,temp);
quotient += temp;
}
}
return quotient;
}
Run Code Online (Sandbox Code Playgroud)
您可以将分子和分母传递给此函数并获得所需的商.
| 归档时间: |
|
| 查看次数: |
58681 次 |
| 最近记录: |