# integer_division_v1.c

May 7th, 2020
189
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /*
2.
3.     integer_division_v1.c
4.
7.
8.
9.     You can find all my C programs at Dragan Milicev's pastebin:
10.
11.     https://pastebin.com/u/dmilicev
12.
13. */
14.
15. #include <stdio.h>
16.
17. int main(void)
18. {
19.     int a,b,div,n=5;
20.     float f_div;
21.
22.     printf("\n Integer division: \n");
23.     printf("\n If a<b then a/b = 0 \n");
24.     printf("\n If a=b then a/b = 1 \n");
25.     printf("\n If a>b then fractional part of the a/b is discarded, \n\tmaking the result an integer. \n");
26.
27.     printf("\n Integer division from -%d to %d is:\n", n, n );
28.     printf("\n   integer \t     float \t\t   difference\n");
29.
30.     for(a=-n; a<=n; a++)
31.     {
32.         for(b=-n; b<=n; b++)
33.         {
34.             if (b==0)       // it is impossible to divide by zero
35.                 continue;
36.             else
37.             {
38.                 div = a / b;
39.                 f_div = (float)a/b;
40.                 printf("\n %2d / %2d = %2d \t %2d / %2d = %8.5f \t diff = %8.5f ",
41.                         a, b, div, a, b, f_div, f_div-div );
42.             }
43.         }
44.         printf("\n");
45.     }
46.
47.     return 0;
48.
49. } // main()
RAW Paste Data Copied