Created
September 8, 2018 20:07
-
-
Save durgaswaroop/d09926c0f4b93a0c126c616224dc1997 to your computer and use it in GitHub Desktop.
C-Programming 25 - Building a Calculator with functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
//-- Function Signatures --// | |
int add(int a, int b); | |
int sub(int a, int b); | |
int mul(int a, int b); | |
int div(int a, int b); | |
float rdiv(int a, int b); | |
main() { | |
int first; | |
printf("Enter first number:"); | |
scanf("%d", &first); | |
int second; | |
printf("Enter second number:"); | |
scanf("%d", &second); | |
printf("%d, %d, %d, %d, %f\n", | |
add(first, second), | |
sub(first, second), | |
mul(first, second), | |
div(first, second), | |
rdiv(first, second) | |
); | |
} | |
//-- Function definitions --// | |
int add(int a, int b){ | |
return a + b; | |
} | |
int sub(int a, int b){ | |
return a - b; | |
} | |
int mul(int a, int b){ | |
return a * b; | |
} | |
int div(int a, int b){ | |
return a / b; | |
} | |
float rdiv(int a, int b){ | |
return (float)a/b; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment