Answer:
2.
(a)
#include <stdio.h>
#include <string.h>
// Declare the House structure
struct House {
char location[20];
char pattern;
int area;
double interestRate;
};
int main() {
// Define a variable called pelangi of type House
struct House pelangi;
// Define another variable called alpha of type House
struct House alpha;
return 0;
}
(b)
#include <stdio.h>
#include <string.h>
// Declare the House structure
struct House {
char location[20];
char pattern;
int area;
double interestRate;
};
int main() {
// Define a variable called pelangi of type House
struct House pelangi;
// Define another variable called alpha of type House
struct House alpha;
// Assign values to the location and interestRate members of alpha
strcpy(alpha.location, "Setapak");
alpha.interestRate = 0.04;
// Assign values to the location and interestRate members of pelangi
strcpy(pelangi.location, "Gelugor");
pelangi.interestRate = 0.04;
// Accept a value for pattern of alpha
printf("Enter a value for pattern of alpha: ");
scanf(" %c", &alpha.pattern);
// Accept a value for area of pelangi
printf("Enter a value for area of pelangi: ");
scanf("%d", &pelangi.area);
return 0;
}
3.
#include <stdio.h>
struct Force {
char name[40];
int pointNumber;
double xForce;
double yForce;
};
int main() {
struct Force wing;
wing.xForce = 15.3;
wing.yForce = 28.5;
wing.pointNumber = 85;
strcpy(wing.name, "DC 10");
printf("Wing name: %s\\", wing.name);
printf("Point number: %d\\", wing.pointNumber);
printf("X force: %lf\\", wing.xForce);
printf("Y force: %lf\\", wing.yForce);
return 0;
}