You must Sign In to post a response.
  • Category: Programming

    Differentiation between ÷ and % operator in C with example.


    Preparing for engineering degree exam? want to get a solution for difference between logical and relational operators on C? Here, our ISC experts shall provide with the main differences and relevant examples to resolve the concerns.

    Following is a question that was asked in the question paper of II/IV B.Tech Degree Examinations,
    (April/May 2015)conducted by Acharya Nagarjuna University for subject Object Oriented Programming Systems, Semester-II

    Q) Differentiate the ÷ operator with % operator illustratively. Enumerate the logical and relational operators in C. Compare their precedence values. [7 Marks]
  • Answers

    3 Answers found.
  • Hello there,

    The oprator "÷" is an division operator in coding it is used as "/" and "%" is the modulus operator.

    "/" operator divides the value and give you the quotient as output where as "%" operator is know as modulus it gives you the remainder as the result.

    Example for "÷"(/) operator:
    12 / 3 = 4
    Here 4 is the output i.e. the quotient.

    Example for "%" operator:
    12 % 3 = 0
    Here 0 is the output i.e. the remainder.

    Thank you.

  • C language supports variety of operators. The different categories of operators supported by C language are as follows.
    1) Mathematical/Arithmatic operators
    2) Relational operators
    3) Logical operators
    4) Short-hand assignment operators
    5) Increment/decrement operators
    6) Conditional operator
    7) Bitwise operators
    the ÷ operator and % operator are the operators from mathematical operators. ÷ operator is used to obtain quotient and % operator is used to obtain remainder, when one number is divided by another number.
    Let us see one example. Below is the program which shows use of ÷ and % operators. In C language ÷(division) operator is shown by / sign and modulus operator is shown by % sign.

    Please include and header files before main function.
    //PROGRAM TO ILLUSTRATE USE OF DIVISION AND MODULUS OPERATOR.
    #include
    #include
    void main(void)
    {
    int a,b,rd,rr;
    clrscr();
    printf("Enter any two numbers\n");
    scanf("%d%d",&a,&b);
    rd=a/b;
    rr=a%b;
    printf("\nResult of division(a/b)which is quotient is %d",rd);
    printf("\nRemainder after division is %d",rr);
    getch();
    }

    Different logical operators are AND(&&), OR(||) and NOT(!) operators. Logical operators AND and OR are used when more than two conditions are required to combine together to get the result.
    In case of AND operator, when all the conditions are true then and then only final answer is true.
    Let us see one daily life example to understood AND operator. If teacher declared that if Raju and Abhi comes, then I will teach the class. In this case the class will be conducted only when both Raju and Abhi comes. In rest of the cases class will not be conducted.
    In case of OR operator, when any one of the condition is true then final answer is true.
    Let us see one daily life example to understood OR operator. If teacher declared that if Raju or Abhi comes, then I will teach the class. In this case the class will not be conducted only when both Raju and Abhi did not comes. In rest of the cases class will be conducted.
    In case of NOT operator, it changes the current state of variable or expression. If current state of expression/variable is true then after applying NOT operator it changes to false and vice-versa.
    if((var=='a')||(var=='e')||(var=='i')||(var=='o')||(var=='u')) is called as logical expression.
    Different relational operators are <(less than), >(greater than), <=(less than or equal to), >=(greater than or equal to), ==(comparison). !=(Not equal to).
    Normally relational operators are used to check the relation between two entities.
    e.g. if Abhay is 17 years college student then to check whether Abhay is eligible for voting or not? we use age>=18 condition. Here age>=18 is a relational expression.

    Precedence means priority of operators. Precedence of relational operators is higher than logical operators.

  • Operator is basically use to perform the arithmetical, logical and relational operations.
    C programming language have a number of operators:

    (A) - Arithmetic Operator : - An arithmetic operator is basically use to perform the mathematical operations like addition(+), subtraction(-), multiplication(*), division(/) and modulo(%).
    addition(+) operator is use for perform the addition of operands.
    subtraction(-) operator is use for perform the subtraction of operands.
    multiplication(*) operator is use for perform the multiplication of operands.
    division(/) operator is use for perform the division of operands and give us quotient of them.
    modulo(%) operator is use for calculate the remainder of operands on division as a result and it discard the quotient.
    So the main difference between the (/) and (%) is that divison operator is used to calculate the quotient while the modulo operator is used to calculate the remainder over division.
    Suppose you have two variables x = 6, y = 4
    In normal calculation you will get the result of (6/4) = 1.5. but you will get 1 instead of getting 1.5 as result in programming. Because both variables are of the integer types so that it will neglect the decimal part.
    If you want to apply the modulo operator on the same variable (6 % 4) then you will get 2 as result . Because % operator calculates the remainder only.
    Below is the small example of Arithmetic operator that will cover all operations inside the Arithemtic Operator.
    #include
    int main(void) {
    // your code goes here
    int x = 6, y = 4;
    printf("%d %d %d %d %d", (x+y), (x-y), (x*y), (x/y), (x%y));
    return 0;
    }

    (B) - Logical Operator :- Logical Operator is basically used for desicion making that will return either 0(false) or 1(true) . Logocal operator mainly have three operator that is Logical AND(&&), Logical OR(||) and LogicalNot(!).
    LogicalAND return true only if all operands are true.
    LogicalOR return true if any one of operand is true.
    LogicalNot return true if operand is false and it return false when operand is true.
    Below is the small example of Logical operator that will cover all operations inside the Logical Operator.
    #include
    int main(void) {
    // your code goes here
    int x = 6, y = 4;
    printf("%d %d %d ", (x&&y), (x||y), (x!=y));
    return 0;
    }

    (C) - Relational Operator :- Relational Operator is basically use for checking relation between two operands. It relation is true it return true(1) and if relation is false it return false(0). There are some relational operator listed below:
    Less than(<)
    Greater than(>)
    Less than or equal to(<=)
    Greater than or equal to(>=)
    Equal to(==)
    Not equal to(!=)
    Below is the small example of Relational operator that will cover all operations inside the Relational Operator.
    #include
    int main(void) {
    // your code goes here
    int x = 6, y = 4;
    printf("%d %d %d %d %d %d", (xy), (x<=y), (x>=y), (x==y), (x!=y));
    return 0;
    }

    These above three are most useful operator in C. Except to this C have other operators as well like:
    Increment(++) and Decrement Opeartor(--) -: These both operator are basically use for changing the value of the operand by 1. Increment operator change the value by increaing 1 while Decrement operator change the value by decreasing by 1.
    Assignment Operator -: This operator is used for assigning the value to the variable. These are also have various operators like (=, +=, -=, *=, /=, %=)
    Bitwise Operator -: This operator is basically used for performing bitwise operations like:
    Bitwise AND(&)
    Bitwise OR(|)
    Bitwise exclusive OR(^)
    Bitwise complement(~)
    Shift left(<<)
    Shift right(>>)



    I hope this answer will be useful.


  • Sign In to post your comments