Saturday, May 16, 2009

C Programming - Operators

In this tutorial you will learn about Operators, Arithmetic operators, Relational Operators, Logical Operators, Assignment Operators, Increments and Decrement Operators, Conditional Operators, Bitwise Operators and Special Operators.

Examples of arithmetic operators are
x + y
x - y
-x + y
a * b + c
-a * b

etc., here a, b, c, x, y are known as operands. The modulus operator is a special operator in C language which evaluates the remainder of the operands after division. Example

#include //include header file stdio.h void main() //tell the compiler the start of the program { int numb1, num2, sum, sub, mul, div, mod; //declaration of variables

scanf (“%d %d”, &num1, &num2); //inputs the operands sum = num1+num2; //addition of numbers and storing in sum.

printf(“\n Thu sum is = %d”, sum); //display the output sub = num1-num2; //subtraction of numbers and storing in sub.

printf(“\n Thu difference is = %d”, sub); //display the output mul = num1*num2; //multiplication of numbers and storing in mul.

printf(“\n Thu product is = %d”, mul); //display the output div = num1/num2; //division of numbers and storing in div.

printf(“\n Thu division is = %d”, div); //display the output mod = num1%num2; //modulus of numbers and storing in mod.

printf(“\n Thu modulus is = %d”, mod); //display the output }

No comments:

Post a Comment