Mathematical Operations in C

Discussion in 'C' started by lionaneesh, Jun 15, 2011.

  1. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    In this tutorial we’ll be learning some mathematical operations in C (multiplications, divisions , additions , subtractions , modulus) So let’s get started

    Almost all mathematical operations in C follow the following syntax :-

    Code:
    [number] [operator] [number] …
    
    The ‘…’ indicates that any number of terms (>2) can be operated in C.

    Addition

    Code:
    [Number] + [Number]
    
    Eg :-

    Code:
    1 + 2
    
    Subtraction :-

    Code:
    [Number] – [Number]
    
    Multiplication :-

    Code:
    [Number] * [Number]
    
    Division:-

    Code:
    [Number] / [Number]
    
    Modulus:-

    Code:
    [Number] % [Number]
    
    Tasks :-

    Now that we know how to carry Different mathematical operations in C, So let’s now use this knowledge to do mathematical tasks (I suggest the readers to try out first before seeing the solutions)

    1. Make a C program to print the sum of 3 and 5 on to the screen.
    Code:
    #include<stdio.h>
    
    int main()
    {
        int sum = 3 + 5;
        printf("%d\n",sum);
        return(0);
    } 
    2. Make a C program to print out the product of 99 and 12345 on the screen
    Code:
    #include<stdio.h>
    
    int main()
    {
        int product = 99 * 12345;
        printf("%d\n",product);
        return(0);
    }
    
    3. Make a C program to print out the difference of 88 and 77 on the screen.
    Code:
    #include<stdio.h>
    
    int main()
    {
        int difference = 88 - 77;
        printf("%d\n",difference);
        return(0);
    }
    
    I hope you liked this tutorial , Stay tuned for more
     
  2. jam143

    jam143 New Member

    Joined:
    Jul 1, 2011
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    n/a
    Location:
    philippines
    how about having other mathematical equations.. for example √ (this is square root) thank you.
     
  3. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    C provides us a Set of Functions for dealing with under roots , squares , cubes etc. We'll deal with that in the later tutorials
     
  4. jam143

    jam143 New Member

    Joined:
    Jul 1, 2011
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    n/a
    Location:
    philippines
    ahh.. okay I get it.. thank you.. :)
     
  5. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    My Pleasure !
     
  6. Sarwat

    Sarwat New Member

    Joined:
    Nov 5, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Lecturer
    Location:
    Karachi-Pakistan
    prefix and postfix increment and decrement operators should be covered
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice