Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
#include <stdio.h> /* Prototypes — declared before main so main can call them */ int add(int a, int b); double power(double base, int exp); unsigned long factorial(unsigned int n); int main(void) { printf("add(3, 4) = %d ", add(3, 4)); printf("power(2.0, 10) = %.0f ", power(2.0, 10)); printf("factorial(10) = %lu ", factorial(10)); return 0; } /* Definitions */ int add(int a, int b) { return a + b; } double power(double base, int exp) { double result = 1.0; for (int i = 0; i < exp; i++) result *= base; return result; } /* Recursive factorial */ unsigned long factorial(unsigned int n) { if (n <= 1) return 1; return n * factorial(n - 1); }
Result
Open