A structure with appropriate variables to store the information (years, building
ID: 3832197 • Letter: A
Question
A structure with appropriate variables to store the information (years, building, wage) from the table w. Declare two instances of the structure (named "adam" and "beth") and store the information in the structures. (Full program is not required). program that includes a function, outside of the "main" function, that will accept two pointers s) as arguments. The function should switch the values of the variables they point to. "main" function, have the user input two integers and call the function to switch the values.Explanation / Answer
PROGRAM CODE:
1)
#include <stdio.h>
struct employee
{
int years;
char buildingCode;
double wage;
};
int main(void) {
struct employee adam, beth;
adam.years = 3;
adam.buildingCode = 'C';
adam.wage = 16.05;
beth.years = 5;
beth.buildingCode = 'B';
beth.wage = 21.75;
return 0;
}
2)
#include <stdio.h>
void swap(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
int main(void) {
int a, b;
printf(" Enter integer a: ");
scanf("%d", &a);
printf(" Enter integer b: ");
scanf("%d", &b);
printf(" Before Swapping: a=%d b=%d", a, b);
swap(&a, &b);
printf(" After swapping: a=%d b=%d", a, b);
return 0;
}
OUTPUT:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.