You are on page 1of 1

2

Prepare C Introduction Functions in C Exit Full Screen View 


 
  

Change Theme Language C


Objective
285 more points to get your gold badge!
Functions in will
In this challenge, you C learn
 simple usage of functions in C.
2
3 int max_of_four(int a,int b,int c,int d){
Rank: 132970 | Points: 215/500
C language
Problem


Functions are a bunch of statements grouped together. A 4     int sum=a;
function is provided with zero or more arguments, and it 5     
6     if(b>sum){
executes the statements on it. Based on the return type, it 7         sum=b;}
either returns nothing (void) or something. 8     if(c>sum){
9         sum=c;} 
You have successfully solved Functions in C Share    Tweet
10     if(d>sum){
You are now 285 points away from
A sample syntax for a function is 11 the gold level for your c badge.
        sum=d;
Submissions

12     }return sum;}
Try the next
13 challenge
int main() {
return_type function_name(arg_type_1 a 14     int a, b, c, d;
... 15     scanf("%d %d %d %d", &a, &b, &c, &d);
... 16     int ans = max_of_four(a, b, c, d);
... 17     printf("%d", ans);
Problem [if return_type
Submissionsis non void]Leaderboard Editorial
18     return 0;}
return something of type `retu
} Line: 8 Col: 15
Leaderboard

 Upload Code as File Run Code Submit Code


For example, a function to read four variables and return the
Test against custom input
sum of them can be written as

int sum_of_four(int a, int b, int c, i


int sum = 0;
sum += a;
Discussions

sum += b;
sum += c;
Congratulations
You solved this challenge. Would you like to Next Challenge
sum += d;
return sum; challenge your friends?
}

Test case 0
Compiler Message
Editorial

+= : Add and assignment operator. It adds the


Success
a += b is equivalent to a = a + b; Test case 1

Test case 2 Input (stdin) Download


Task
1 3
Write a function int max_of_four(int a, int b, int c,
Test case 3 2 4
int d) which reads four arguments and returns the greatest
3 6
of them.
Test case
Blog | Scoring | Environment | FAQ | About Us | Support 4
| Careers 5
| Terms 4Of Service | Privacy Policy
Note

You might also like