We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C
- Introduction
- Functions in C
- Discussions
Functions in C
Functions in C
+ 0 comments #include<stdio.h> #include<stdlib.h> #include<time.h> #include<math.h> #include<ctype.h> int max_of_four(int a,int b,int c,int d); int main() { int a,b,c,d,res; 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; } } scanf("%d\n%d\n%d\n%d",&a,&b,&c,&d); res=max_of_four(a,b,c,d); printf("%d",res); return 0; }
+ 0 comments include
include
using namespace std;
int max_of_four(int a, int b, int c, int d) { int sum;
sum = ((a > b) ? a : b); sum = ((sum > c ) ? sum : c); sum = ((sum > d ) ? sum : d); return sum;
}
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 int ans; if(ans
+ 1 comment #include <stdio.h> /* 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) { // if a is the maximum switch (a > b && a > c && a > d) { case 1: return a; case 0: // if b is the maximum switch (b > a && b > c && b > d) { case 1: return b; case 0: // if c is the maximum switch (c > a && c > b && c > d) { case 1: return c; case 0: // if d is the maximum return d; } } // in this case all numbers are equls default: return a; } }
+ 0 comments int max_of_four(int a, int b, int c, int d) { int res = 0; if (a > res) res = a; if (b > res) res = b; if (c > res) res = c; if(d > res) res = d; return res; }
Load more conversations
Sort 728 Discussions, By:
Please Login in order to post a comment