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
Sort by
recency
|
845 Discussions
|
Please Login in order to post a comment
This program defines a function max_of_four to find and return the greatest of four integers using basic comparisons. It's a simple example of how to use functions in C for modular and reusable code. Cricketbuzz.com
include
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);
} int max_of_four(int a, int b, int c, int d) { int ans; if (a > b && a > c && a > d) ans = a; else if (b > c && b > d) ans = b; else if (c > d) } ans = c; else ans = d;
include
/* 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 ans=a; if(b>ans) ans=b; if(c>ans) ans=c; if(d>ans) ans=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);
}
Functions in C are essential for writing modular, reusable, and organized code. Sky1exch login