Skip to content

Instantly share code, notes, and snippets.

@durgaswaroop
Created September 8, 2018 20:07
Show Gist options
  • Save durgaswaroop/d09926c0f4b93a0c126c616224dc1997 to your computer and use it in GitHub Desktop.
Save durgaswaroop/d09926c0f4b93a0c126c616224dc1997 to your computer and use it in GitHub Desktop.
C-Programming 25 - Building a Calculator with functions
#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