Write a complete C program that performs the following: o Defines a structure na
ID: 3844407 • Letter: W
Question
Write a complete C program that performs the following: o Defines a structure named My Struct that contains the following members: string variable named str (up to 50 characters, including terminator) integer variable named ivar double variable named dvar o Within the main function, declares a variable named A of type Mystruct. It should be declared and initialized at the same time with the following values: "Hello", 21, and 3.14. o Declares a second variable named B also of type Mystruct. It should be initialized separately with the values "Goodbye", 36, and 12.34. o Prints all the members of both A and B by using the dot struct member operator. Build and test your program to verify that the results match the sample output. Sample Run (output): Members of A: str Hello Ivar 21 dvar, 3.140000 Members of B: 3 str Goodbye ivar, 36 gvar, 12.340000 Copy and paste your complete program here:Explanation / Answer
Structure12.c
#include<stdio.h>
#include<stdlib.h>
struct Mystruct
{
char str[50];
int ivar;
double dvar;
}A={"Hello",21,3.14},B={"Goodbye",36,12.34};
int main()
{
struct Mystruct *p=&B;
struct Mystruct *q=&A;
printf("The Members of B is : ");
printf("Str=%s ivar=%d dvar=%f ",p->str,p->ivar,p->dvar);
printf(" ");
printf("The Members of A is : ");
printf("Str=%s ivar=%d dvar=%f ",q->str,q->ivar,q->dvar);
return 0;
}
Structure1.c
#include<stdio.h>
#include<stdlib.h>
struct Mystruct
{
char str[50];
int ivar;
double dvar;
}A={"Hello",21,3.14}, B={"Goodbye",36,12.34};
int main()
{
printf("The Members of A is : ");
printf("Str=%s ivar=%d dvar=%f ",A.str,A.ivar,A.dvar);
printf("The Members of B is : ");
printf(" ");
printf("Str=%s ivar=%d dvar=%f ",B.str,B.ivar,B.dvar);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.