In: Computer Science
(MUST BE DONE IN C (NOT C++))
Define two different structures at the top of your program. Define each structure with exactly three members (each member has to be a different datatype). You may set them up whichever way you want. Don’t forget your 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.
Notice the words “define”, “declare” and “initialize”. Using them properly with the guidelines in terms of programming is going to help a lot in understanding this problem.
Structure data type:
A structure is a user-defined data type that is a collection of different data types. The structure data member can be accessed by using the structure variable and dot operator or structure pointer variable and arrow operator.
The required program source code is given below:
#include <stdio.h>
//define structure
struct abc
{
//structure member
int a;
float b;
char c;
};
//define structure
struct def
{
//structure member
double d;
unsigned int e;
long int f;
};
int main()
{
//structure variable declaration
struct abc st;
struct def st1;
//initialize the structure member
st.a = 10;
st.b = 20.0f;
st.c = 'm';
st1.d = 2500;
st1.e = 32;
st1.f = 430;
//display the values of the structure member
printf("The structure members values are given below:\n");
printf("a = %d\n", st.a);
printf("b = %f\n", st.b);
printf("c = %c\n\n", st.c);
printf("d = %lf\n", st1.d);
printf("e = %u\n", st1.e);
printf("f = %ld\n", st1.f);
return 0;
}
OUTPUT:
The structure members values are given below:
a = 10
b = 20.000000
c = m
d = 2500.000000
e = 32
f = 430