Advertisement
Mukezh

Session 3 Modulus

Dec 3rd, 2020 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. Modulus Operator %
  2. Result is always Remainder
  3.  
  4. a= 5 % 2; 1
  5. a= 18 % 5; 3
  6. a= 33 % 4; 1 4X8=32 rem = 1
  7. a= -5 % 2 ; -1
  8. a= 5 % -2 ; 1 5/-2; -2
  9. Divident = Divisor X Quotient + Remanider
  10. 5 = 3
  11.  
  12.  
  13. 5/2 Quo=2 Rem=1
  14. a=5/2; 2
  15. a=5%2; 1
  16.  
  17. Example
  18.  
  19. Divident 5 Divident = Divisor X Quo + Rem
  20. Divisor 2 5 = 2 X 2 + 1 = 4+1 = 5
  21. Q 2
  22. R 1
  23. %%%%%%%%%%%
  24. a= 5 / -2 ; -2 Divident = Divisor X Quo + Rem
  25. a= 5 % -2 ; -1 X 1 5 = -2 X -2 + (-1) = 4 + (-1)= 3
  26. %%%%%%%%%%%
  27. Rule for Modulus
  28. 1. Result is always Remainder
  29. 2. Result Sign is always same as numerator.
  30. 3. Result sign does not depend on sign of Denominator.
  31. 4. Mod (%) operator does not apply on float value.
  32. C Lang
  33. +/+ => + + % + => +
  34. +/- => - + % - => +
  35. -/+ => - - % + => -
  36. -/- => + - % - => -
  37.  
  38. %%%%%%%%%%%
  39. a=5.0 / 2; 2.5 Quotient
  40. a=5.0 % 2; 1 Remainder
  41. Divident = Divisor X Quo + Rem
  42. 5.0 = 2 X 2.5 + 1 = 5 + 1 = 6
  43. %%%%%%%%%%%
  44. a= 12 % 10; 2 num % 10 will gives unit value as it result
  45. a= 154 %10; 4
  46. a= 456231 %10; 1
  47. a=-75 %10; -5
  48. a= 20 % -10; 0
  49. a= 24 % -10; 4
  50.  
  51. a= 8 % 10; 8 In Mod Operator, When num<Denominator Result always numerator
  52. a= 3 % 13; 3
  53. a= 8 % 45; 8
  54. a= 32 % 78; 32
  55.  
  56.  
  57.  
  58. Arithematic Operator
  59. * / %
  60. + -
  61. = (Assignment Operator)
  62.  
  63. Data Type
  64. int %d(decimal) or %i(int) ==> Format Specifier
  65. char %c
  66. float %f
  67.  
  68. Basic C Program
  69. void main()
  70. {
  71.  
  72. }
  73.  
  74. Header file is Optional (#include<_____>)
  75.  
  76. Mukesh Height 150cm
  77. School Dis 10km
  78.  
  79. C-Tokens (Unit)
  80. Keywords
  81. Operator
  82. Seperator ;
  83. Variable
  84. Constant
  85.  
  86. void Tokens
  87. main() Keyword: void 1
  88. { operator: () () 4
  89. printf Seperators: {} ; 3
  90. ( Identifier : main printf 2
  91. "Hello World" constant : "Hello world" 1 Total Tokens=11
  92. )
  93. ;
  94.  
  95.  
  96. }
  97. In C program, There can be
  98. N no of spaces, N no of Tab, N no of New Lines Between any 2 tokens
  99.  
  100.  
  101. void main()
  102. {
  103. printf("Hello World");
  104. }
  105.  
  106.  
  107.  
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement