In: Computer Science
Be sure to use only C for the Programming Language in this problem.
Before we start this, it is imperative that you understand the words “define”, “declare” and “initialize” in context of programming. It's going to help you a lot when following the guidelines below.
Let's begin! Define two different structures at the top of your program. be sure to define each structure with exactly three members (each member has to be a different datatype). You may set them up however you want (so long as it runs without issue of course). Remember to use semicolons.
- Inside main, declare two structures. One for each of the two structures you defined.
- Then, initialize each one of the members manually (the three members of your first structure and the three elements of your second structure).
- Lastly, print out all six members with their respective message.
#include <stdio.h>
/*Defining the Structure1*/
struct Company
{
int cregistration_no;
char *cname;
int cphone_number;
};
/*Defining the Structure2*/
struct Employee
{
int eid_no;
char *ename;
int ephone_number;
};
int main()
{
/* Here company is the variable of structure Company*/
struct Company company;
/*Now we are assigning the values of each struct member here*/
company.cregistration_no = 12345;
company.cname = "Apple";
company.cphone_number = 234567;
/* Here employee is the variable of structure Employee*/
struct Employee employee;
/*Now we are assigning the values of each struct member here*/
employee.eid_no = 142134;
employee.ename = "Sumit Kumar";
employee.ephone_number = 236785;
/*Now we are going to displaying the values of struct members */
printf("Registration number of company is: %d", company.cregistration_no);
printf("\n Company name is: %s", company.cname);
printf("\ncompany Phone Number is: %d", company.cphone_number);
/*Now we are going to displaying the values of struct members */
printf("\n\n\nEmployee id is: %d", employee.eid_no);
printf("\n Employee name is: %s", employee.ename);
printf("\nEmployee Phone Number is: %d", employee.ephone_number);
return 0;
}
Registration number of company is: 12345
Company name is: Apple
company Phone Number is: 234567
Employee id is: 142134
Employee name is: Sumit Kumar
Employee Phone Number is: 236785
Please refer to the screenshoot of the code too understand the indentation of the code.