|
| Total Answers and Comments: 3 |
Last Update: July 16, 2008 Asked by: Rashi Rathi |
|
| | |
| |
| |
November 29, 2007 13:35:48 | #1 |
| sarathi trichy |
|
Member Since: October 2007 Contribution: 106 |
RE: Without using /,% and * operators. write a function to divide a number by 3.
| #include<stdio.h> #include<conio.h> void main() { int i,n; float j=0; clrscr(); printf("enter the no"); scanf("%d",&n); for(i=n;i>2;i=i-3) { j=j+1; if(i==4) { j=j+1.333333; } if(i==5) { j=j+1.666666; } } printf("%f",j); getch(); }
|  | | Is this answer useful? Yes | No | 1 0 | Overall Rating: +1 |
|
| |
|
December 11, 2007 05:32:04 | #2 |
| purnendu_patra |
|
Member Since: December 2007 Contribution: 2 |
RE: Without using /,% and * operators. write a function to divide a number by 3.
| The number is N, the decimal places to which the division will be done is D.
int quot=0,remainder=0,rem=0; int x=0;
Void DivisionBySubtraction(N,D) { while(N>=3) { N-=3; ++quot; } if (N==0) cout<<"quotient="<<quot; else { while(x<D) { N*=10; while(N>=3) { N-=3; rem++; } remainder = remainder*10+rem; if (N==0) break; ++x; } } cout<<"remainder="<<remainder;
} |  | | Is this answer useful? Yes | No | 1 0 | Overall Rating: +1 |
|
| |
Go To Top
|