Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- integer_division_v1.c
- Task:
- https://web.facebook.com/photo.php?fbid=755125075233210&set=gm.1573057319519779&type=3&theater&ifg=1
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- int main(void)
- {
- int a,b,div,n=5;
- float f_div;
- printf("\n Integer division: \n");
- printf("\n If a<b then a/b = 0 \n");
- printf("\n If a=b then a/b = 1 \n");
- printf("\n If a>b then fractional part of the a/b is discarded, \n\tmaking the result an integer. \n");
- printf("\n Integer division from -%d to %d is:\n", n, n );
- printf("\n integer \t float \t\t difference\n");
- for(a=-n; a<=n; a++)
- {
- for(b=-n; b<=n; b++)
- {
- if (b==0) // it is impossible to divide by zero
- continue;
- else
- {
- div = a / b;
- f_div = (float)a/b;
- printf("\n %2d / %2d = %2d \t %2d / %2d = %8.5f \t diff = %8.5f ",
- a, b, div, a, b, f_div, f_div-div );
- }
- }
- printf("\n");
- }
- return 0;
- } // main()
Add Comment
Please, Sign In to add comment