IN C PROGRAMMING: struct bank_book { char firstname[20]; char lastname[20]; char
ID: 3715568 • Letter: I
Question
IN C PROGRAMMING:
struct bank_book {
char firstname[20];
char lastname[20];
char ss_id[10];
unsigned short bankId;
double balance;
} (this is the struct im using for this problem)
(2) Define a variable called myAccountof type struct bank book, declare and initialize an array of 1000 elements called THE_BANK of type struct bank book; You should initialize the array so that all fields are assigned zero (ii) assign to the 5th element of the THE_BANK array the following information: John Smith, 21465, 990123411, 3201.23 (iv) Assume no padding takes place how many bytes is required to an identifier of type struct bank book (v) suppose that the array THE BANK is located at the address 7200 and we assign cptr- THE_BANK +5 then determine cptrExplanation / Answer
#include<stdio.h>
//declaring structure
struct bank_book
{
char firstname[20];
char lastname[20];
char ss_id[10];
unsigned short bankId;
double balance;
};
int main()
{
//2)
//i
//declaring variable
struct bank_book myAccount;
//defining
printf("Enter first name:");
scanf("%s",myAccount.firstname);
printf("Enter last name:");
scanf("%s",myAccount.lastname);
printf("Enter ssid:");
scanf("%s",myAccount.ss_id);
printf("Enter bankId:");
scanf("%hu",&myAccount.bankId);
printf("Enter balance:");
scanf("%lf",&myAccount.balance);
//declaring(ii)
struct bank_book THE_BANK[1000];
//(iii) assigning values to fifth element
printf("Enter first name:");
scanf("%s",THE_BANK[4].firstname);
printf("Enter last name:");
scanf("%s",THE_BANK[4].lastname);
printf("Enter ssid:");
scanf("%s",THE_BANK[4].ss_id);
printf("Enter bankId:");
scanf("%hu",&THE_BANK[4].bankId);
printf("Enter balance:");
scanf("%lf",&THE_BANK[4].balance);
//printing out
printf("Name: %s %s ",THE_BANK[4].firstname,THE_BANK[4].lastname);
printf("ssid :%s ",THE_BANK[4].ss_id);
printf("BankId :%hu ",THE_BANK[4].bankId);
printf("balance: %lf ",THE_BANK[4].balance);
//(iv) number of bytes required
printf("Number of bytes required :%d ",sizeof(struct bank_book));
//(v) the cptr would be cptr = 7200+(sizeof(bank_book)*5)
return 0;
}
output:
Enter first name:sura
Enter last name:s
Enter ssid:10
Enter bankId:100
Enter balance:1000
Enter first name:John
Enter last name:Smith
Enter ssid:21465
Enter bankId:990123411
Enter balance:3201.23
Name: John Smith
ssid :21465
BankId :5523
balance: 3201.230000
Number of bytes required :64
Process exited normally.
Press any key to continue . . .