Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int sum(int a,int b, int f);
- int main()
- {
- int a;
- int b;
- int result = 0;
- printf("Enter two integers: ");
- scanf("%d %d", &a,&b);
- if(a < b){
- result = sum(a, b, 1);
- } else if(a > b) {
- result = sum(a, b, -1);
- } else {
- result = a + b;
- }
- printf("Result: %d", result);
- return 0;
- }
- int sum(int a, int b, int f) {
- if(a == b) {
- return a;
- } else {
- return sum(a + (f * 1),b , f) + a;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement