a program to read the data for the customer, calculate the interest and service charge, and print the customer’s name, average balance, interest, and service charge.

//calculate interest and service charge for bank customer #include <stdio.h> int main() { char customer[30], acctNum[30]; double avgBalance, interest, service; int numTrans; printf(“Name? “); gets(customer); printf(“Account number? “); gets(acctNum); printf(“Average balance? “); scanf(“%lf”, &avgBalance); printf(“Number of transactions? “); scanf(“%d”, &numTrans); interest = avgBalance * 0.06; service = numTrans * 0.50; printf(“\nName: %s\n”, customer); printf(“Average balance: … Read more

Arrays of Structures & Unions in C

Since structures are data types that are especially useful for creating collection items, why not make a collection of them using an array? Similarly, we can create array of Unions. The following code snippet shows how to create an array of structures and access a particular structure element’s member. struct student { int rno; char … Read more

Union: Accessing Union Members & Nesting in C

To access union members we can use dot operator (.) between union variable and union member name as follows: <Union-Variable-Name>.<MemberAddress> For example, to access marks of union student we can do as follows: union student std2; std2.marks = 20; Now, the data member percentage of union student also contains the same value 20 but in … Read more

Union: Definition, Declaration & Initialization in C

Union, is a collection of variables of different types, just like a structure, however a union can only store information in one field at one time. This means, a union can be viewed as a variable type that can contain many different variables as members (like a structure), but only actually holds one of them … Read more

Nesting of Structures in C

A Structure can contain other Structure variables as members. This is called Nesting of Structures. For example address structure is a structure. We can define a nested structure called customer which contains address structure as follows: struct address { int house_number; char street_name[50]; int zip_code; char country[50]; }; struct customer { char name[50]; structure address … Read more

Initialization & Accessing Structure Members in C

C programming language treats a structure as a user-defined data type; therefore you can initialize a structure like a variable. Here is an example of initialize product structure: struct product { char name[50]; double price; } book = { “C programming language”, 40.5 }; In above example, we defined product structure, then we declare and … Read more

Structure Declaration in C

The first way is to declare a structure variable immediately after the structure definition, as follows: struct address { int house_number; char street_name[50]; int zip_code; char country[50]; } struct_var1, struct_var2; In the second way, you can declare the structure variable at a different location after structure definition. Here is structure declaration syntax: struct address { … Read more