C examples for Operator:Arithmetic Operator
Demonstrates math operators, and the different types of division
#include <stdio.h> int main()//from w w w .j av a2 s .co m { float a = 19.0; float b = 5.0; float floatAnswer; int x = 19; int y = 5; int intAnswer; floatAnswer = a / b; printf("%.1f divided by %.1f equals %.1f\n", a, b, floatAnswer); floatAnswer = x /y; //Take 2 creates an answer of 3.0 printf("%d divided by %d equals %.1f\n", x, y, floatAnswer); intAnswer = a / b; printf("%.1f divided by %.1f equals %d\n", a, b, intAnswer); intAnswer = x % y; // This calculates the remainder (4) printf("%d modulus (i.e. remainder of) %d equals %d", x, y, intAnswer); return 0; }