- Prepare
- C
- Introduction
- Functions in C
- Discussions
Functions in C
Functions in C
+ 0 comments include
int max_of_four(int a, int b, int c, int d){
if(a>=b && a>=c && a>=d) return a; else if(b>=a && b>=c && b>=d) return b; else if(c>=a && c>=b && c>=d) return c; else return d; } int main() { int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); int ans = max_of_four(a, b, c, d); printf("%d", ans);
return 0; }
+ 0 comments include
int add(int x, int y) { return x + y; }
int main() { int a = 10, b = 20, sum; sum = add(a, b); printf("The sum of %d and %d is %d\n", a, b, sum); return 0; }
+ 0 comments #include <iostream> #include <cstdio> using namespace std; /* Add `int max_of_four(int a, int b, int c, int d)` here. */ int max_of_four(int a, int b, int c, int d); int main() { int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); int ans = max_of_four(a, b, c, d); printf("%d", ans); return 0; } int max_of_four(int a, int b, int c, int d) { int max; max=a; if(b>max){ max=b; } if(c>max){ max=c; } if(d>max){ max=d; } return max; }
+ 0 comments include
/* Add
int max_of_four(int a, int b, int c, int d)
here. */ int max_two(int a, int b){ return a > b ? a : b; }int max_of_four(int a, int b, int c, int d){ return max_two(a, b) > max_two(c, d) ? max_two(a, b) : max_two(c, d); }
int main() { int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); int ans = max_of_four(a, b, c, d); printf("%d", ans);
return 0;
}
+ 1 comment What is the error of this ?
include
/* Add
int max_of_four(int a, int b, int c, int d)
here. */int main() { int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); int ans = max_of_four(a, b, c, d); printf("%d", ans);
return 0;
} int max_of_four(int a, int b,int c,int d){ int max1,max2,max3,max4;
if(a>b && a>c&& a>d) max1=a; else if(b>a && b>c&& b>d) max2=b; else if(c>a && c>b&& c>d) max3=c; else if(d>a && d>b&& d>c) max4=d; else printf("error!!"); return max1,max2,max3,max4;
}
Sort 673 Discussions, By:
Please Login in order to post a comment