Function Definition in C
Level 4116 keystrokes
Defines a function that calculates the square of a number and calls it from main.
C code
// Define a function that takes an int and returns an int1int square(int n) { // Calculate and return the square of n2 return n * n;3}4 // Main function - program entry point5int main() { // Call square(5) and print result: 256 printf("%d\n", square(5)); // Call square(12) and print result: 1447 printf("%d\n", square(12)); // Return 0 to indicate successful execution8 return 0;9}Output
25 144
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C code and how often they appear.
(× 6)× 6;× 4"× 4,× 2{× 2}× 2\× 2%× 2*× 1