Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

C example to define functions for arithmetic operations

//Lab 1- Bryan Regn 
// Created 9/6/17 Last updated 9/9/17

//main 
#include <stdio.h>
#include <math.h>


//math.c
//all the following functions require their specific Operator (+,-,*,/,%) and two integers to correctly call the function
//Adds two integers together prints back their sum
void add(int num1, int num2){
   int sum = 0; 
   sum = num1 + num2;
   printf("\n%d",sum);
}
//subtracts two integers prints back the difference
void sub(int num1, int num2){
    int difference = 0;
    difference = num1 - num2;
    printf("\n%d",difference);
}
//multiplies together two integers prints back product
void mul(int num1, int num2){
    int product = 0;
    product = num1*num2;
    printf("\n%d",product);
}
//divides two integers prints back answer
void divide(int num1, int num2){
    int division = 0;
    division = num1/num2;
    printf("\n%d",division);
}
//divides two integers prints back remainder of answer
void modulus(int num1, int num2){
    int result = 0; //remainder was a reserved word and didnt want to use that
    result = num1%num2;
    printf("\n%d",result);
}

//main file used to check user inputs and call different mathmatical operations
int main()
{
    add(10,20);
    sub(10,20);
    mul(10,20);
    divide(10,20);
    modulus(10,20);
    return 0;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.