function-statement

title: "courses/c-course - function-statement.md"

- **fileName**: function-statement
- **Created on**: 2024-06-06 14:57:04

function for write some code and reuse the code any place you went

Example

	function sayWelcome() {
		printf("welcome");
	};
	int main() {
		sayWelcome();
		sayWelcome();
		sayWelcome();
		return 0;
	}
if the function gone take parameters must specify the type for the param

Example

	function sayWelcome(char name[], int age) {
		printf("welcome, %s, your age is : %d", name, age);
	};
	int main() {
		sayWelcome("yossef", 20);
		sayWelcome("ahmed", 30);
		sayWelcome("farouk", 50);
		return 0;
	}

# Recursive Functions

example code get the factorial ( for example 4 = 4 * 3 * 2 * 1)

// Recursive Function to calculate Factorial of a number 
int factorial(int n) {
  if (n <= 0) return 1;
  return n * factorial(n - 1);
};

int main() {
  int n = 4;
  printf("\nthe factorial for number %d => %d",n , factorial(n));
  return 0;
}

continue: while-whileDo.md
before: if-switch.md