C examples for Operator:Modulus Operator
Calculation with Modulus operator
#include <stdio.h> int main(void) { int cookies = 45; // Number of cookies in the jar int children = 7; // Number of children int result = 0; // Number of cookies per child int result2 = 0; // Number of cookies left over result = cookies/children; // Number of cookies per child printf("You have %d children and %d cookies\n", children, cookies); printf("Give each child %d cookies.\n", result); result2 = cookies%children;/*from ww w .j a va2s .co m*/ printf("There are %d cookies left over.\n", result2); return 0; }