0
0
Cprogramming~15 mins

Using printf for output in C - Mini Project: Build & Apply

Choose your learning style9 modes available
Using printf for output
📖 Scenario: You are learning how to show messages on the screen using the printf function in C. This is like writing a note on a board so others can see it.
🎯 Goal: You will write a simple C program that uses printf to display a greeting message.
📋 What You'll Learn
Create a variable to hold a name
Create a variable to hold an age
Use printf to show a message including the name and age
💡 Why This Matters
🌍 Real World
Displaying messages is a basic need in many programs, like showing user information or status updates.
💼 Career
Knowing how to output text is essential for debugging and user interaction in software development.
Progress0 / 4 steps
1
Create variables for name and age
Create a variable called name of type char[] and set it to "Alice". Create an integer variable called age and set it to 30.
C
Need a hint?

Use char name[] = "Alice"; to create the name variable and int age = 30; for the age.

2
Prepare the message format
Create a string variable called message and set it to "Hello, my name is %s and I am %d years old." This will be used as the format for printf.
C
Need a hint?

Use char message[] = "Hello, my name is %s and I am %d years old."; to create the message format string.

3
Use printf to display the message
Use printf with the message variable and pass name and age as arguments to show the full greeting.
C
Need a hint?

Use printf(message, name, age); to print the message with the variables.

4
Print a new line after the message
Add a printf statement to print a new line character \n after the greeting message so the output looks clean.
C
Need a hint?

Use printf("\n"); to add a new line after the message.