my_operation

my_operation
Turn-in directory01_my_operation/
Files to turn inmy_operation.c
Allowed external functionsNone
Type of workFunction
  • Write a program which displays the character c on standard output, followed by a newline.
  • To help you get started, we will provide some code for you to copy/paste/edit. Make sure you understand every line before you hand it in!
  • You need to write a function that takes two integers as parameters and returns the result of the operation specified by the third parameter.
  • The third parameter is a character that can be one of the following: '+', '-', '*', '/' or '%'.
  • If the operation is illegal, the function returns 0.
  • If the third parameter is not one of the above, the function returns 0.
#include <stdio.h>

int my_operation(int a, int b, char operation)
{
    if (operation == '+')
        return a + b;
    return 0;
}


// LAST WARNING
// WHEN YOU ARE ASKED FOR A FUNCTION
// WE WILL USE OUR OWN MAIN FUNCTION TO TEST YOUR EXERCISE
// SO YOU NEED TO REMOVE THE MAIN FUNCTION
// OR COMMENT IT OUT
int main()
{
    char c = '+';
    int a = 1;
    int b = 2;
    int result = my_operation(a, b, c);
    printf("%d\n", result);
    return 0;
}

Example output:

$ ./a.out
3$