0
0
Cprogramming~30 mins

Multiple input and output in C - Mini Project: Build & Apply

Choose your learning style9 modes available
Multiple input and output
📖 Scenario: You are creating a simple program to record the names and ages of three friends. You will input their names and ages, then display this information clearly.
🎯 Goal: Build a C program that takes the names and ages of three friends as input and then prints each friend's name with their age.
📋 What You'll Learn
Use arrays to store names and ages
Use a loop to input data for three friends
Use a loop to output the stored data
Use scanf and printf for input and output
💡 Why This Matters
🌍 Real World
This kind of program helps in collecting and displaying simple records like names and ages, useful in small databases or contact lists.
💼 Career
Understanding multiple inputs and outputs is essential for many programming tasks such as data entry, processing user information, and building interactive applications.
Progress0 / 4 steps
1
Create arrays for names and ages
Declare a 2D character array called names with size 3 by 20 to store three names, and an integer array called ages with size 3 to store their ages.
C
Need a hint?

Use char names[3][20]; to store three names each up to 19 characters plus null terminator.

2
Add a loop to input names and ages
Add a for loop with variable i from 0 to less than 3. Inside the loop, use scanf("%19s", names[i]) to input each name and scanf("%d", &ages[i]) to input each age.
C
Need a hint?

Use a for loop to input data for each friend.

3
Add a loop to output names and ages
Add a for loop with variable i from 0 to less than 3. Inside the loop, use printf("%s is %d years old\n", names[i], ages[i]) to print each friend's name and age.
C
Need a hint?

Use a for loop to print each friend's information.

4
Print the final output
Run the program and input these three friends' data exactly in this order:
Alice 25
Bob 30
Charlie 22
Then print the output exactly as:
Alice is 25 years old
Bob is 30 years old
Charlie is 22 years old
C
Need a hint?

Type the names and ages exactly as shown, then check the printed output.