Input 1. The age of the Person 2. The gender of the Person Output Enter Person's age: 24 Enter Person's gender: M PERSON DETAILS: Age: 24 Gender: Male
( C PROGRAMMING ONLY)
2. Solving a Person's Loneliness
by CodeChum Admin
It's been 1,245 years and our sole Person is getting lonelier each day. This Person definitely needs a partner!
Thus, we need to update our Person's design to have a gender as well and there shall be male and female!
Instructions:
In the code editor, you are provided with the definition of a struct Person. This struct needs an integer value for its age. Furthermore, you are provided with a displayPerson() function which accepts a struct Person as its parameter.
Your task is to first update the struct Person so that it can have a gender as well. For this program, we shall represent a gender with a single character: 'M' for male and 'F' for female.
Then, create a Person, take in an integer user input and a character user input, and then set them as the Person's age and gender respectively.
Finally, call the displayPerson() function and pass that Person you created.
Input
1. The age of the Person
2. The gender of the Person
Output
Enter Person's age: 24
Enter Person's gender: M
PERSON DETAILS:
Age: 24
Gender: Male
![main.c
1 #include<stdio.h>
2
3 typedef struct {
4
int age;
5} Person;
6
7 void display Person (Person);
8
9 int main(void) {
10
11
return 0;
12 }
13
14 void display Person (Person p) {
printf("PERSON DETAILS: \n");
15
16
printf("Age: %d\n", p.age);
17
printf("Gender: ");
if(p.gender == 'M') {
18
19
printf("Male");
20
} else {
21
printf("Female");
22
}
23 }
< > + C
1
1](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5e3ff6ae-c99b-4e78-8035-bb1ba013d8c3%2F733f5dde-5925-443d-a500-50fa98185cdb%2Fu3oqouns_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)