0
0
Cprogramming~15 mins

Why functions are needed - See It in Action

Choose your learning style9 modes available
Why Functions Are Needed
📖 Scenario: Imagine you are cooking a meal and need to wash vegetables multiple times. Instead of washing each vegetable separately every time, you create a simple routine to wash vegetables quickly and use it whenever needed.
🎯 Goal: You will write a small C program that shows how using a function helps avoid repeating the same code multiple times.
📋 What You'll Learn
Create a function called washVegetable that prints washing a vegetable
Call the washVegetable function three times in main
Print messages before and after calling the function to show the process
💡 Why This Matters
🌍 Real World
Functions are like small helpers in cooking or any task. They let us reuse steps without repeating ourselves.
💼 Career
Understanding functions is essential for writing clean, efficient code in any programming job.
Progress0 / 4 steps
1
Create the main function
Write the main function that prints Starting to prepare vegetables.
C
Need a hint?

The main function is where your program starts. Use printf to print the message.

2
Create the washVegetable function
Create a function called washVegetable that prints Washing a vegetable.
C
Need a hint?

Define the function before main. It does not return anything, so use void.

3
Call washVegetable three times in main
Inside main, call the function washVegetable three times after the starting message.
C
Need a hint?

Call the function by writing its name followed by parentheses and a semicolon.

4
Print finishing message
After calling washVegetable three times, print Finished preparing vegetables in main.
C
Need a hint?

Use printf to print the finishing message after the function calls.