0
0
Cprogramming~15 mins

Function parameters - Mini Project: Build & Apply

Choose your learning style9 modes available
Function parameters
📖 Scenario: You are creating a simple calculator program that adds two numbers. You will use a function that takes two numbers as inputs and returns their sum.
🎯 Goal: Build a C program that defines a function with parameters to add two integers and prints the result.
📋 What You'll Learn
Create a function called add that takes two int parameters named a and b.
The add function should return the sum of a and b.
In main, call the add function with the numbers 5 and 7.
Print the result returned by add.
💡 Why This Matters
🌍 Real World
Functions with parameters are used everywhere in programming to reuse code and perform tasks with different inputs, like calculators, games, and apps.
💼 Career
Understanding how to write and use functions with parameters is a fundamental skill for any software developer or programmer.
Progress0 / 4 steps
1
Create the add function with parameters
Write a function called add that takes two int parameters named a and b. The function should return an int. Do not write the function body yet.
C
Need a hint?

Start by writing the function header: int add(int a, int b) and add a placeholder return.

2
Implement the add function body
Inside the add function, write code to return the sum of a and b.
C
Need a hint?

Use the return statement to send back the sum of a and b.

3
Call the add function in main
In the main function, call the add function with the arguments 5 and 7. Store the result in an int variable named result.
C
Need a hint?

Use int result = add(5, 7); to call the function and save the answer.

4
Print the result
Add a printf statement in main to print the value of result. Use "%d\n" as the format string.
C
Need a hint?

Use printf("%d\n", result); to show the sum on the screen.