Friday, 9 October 2026

Dataware housing and data mining


Data Warehousing and Data Mining Lab Practicals

Enterprise: Banking Management System

Software: MySQL 8.0, MySQL Workbench and WEKA

This practical covers source table identification, data warehouse creation, multidimensional data modelling, and data mining applications using WEKA.


Practical 1: Identify Source Tables and Populate Sample Data

Aim

To identify the source tables required for a banking data warehouse.

TablePurposeAttributes
BranchBranch informationBranchID, BranchName, City
CustomerCustomer detailsCustomerID, CustomerName, Gender, Age, BranchID
AccountAccount detailsAccountID, CustomerID, AccountType, Balance
BankTransactionTransaction recordsTransactionID, AccountID, TransactionDate, TransactionType, Amount
LoanLoan informationLoanID, CustomerID, LoanAmount, InterestRate, LoanStatus

Relationships: Branch serves customers, customers own accounts and loans, and accounts contain transactions.

Result: Source tables for the banking data warehouse have been identified.


Practical 2: Create Source Tables and Populate Them

Aim

To create source tables and insert sample banking records.

SQL Code

CREATE DATABASE IF NOT EXISTS BankingSource;
USE BankingSource;

CREATE TABLE Branch (
 BranchID INT PRIMARY KEY,
 BranchName VARCHAR(50),
 City VARCHAR(50)
);

CREATE TABLE Customer (
 CustomerID INT PRIMARY KEY,
 CustomerName VARCHAR(100),
 Gender VARCHAR(10),
 Age INT,
 BranchID INT,
 FOREIGN KEY (BranchID) REFERENCES Branch(BranchID)
);

CREATE TABLE Account (
 AccountID INT PRIMARY KEY,
 CustomerID INT,
 AccountType VARCHAR(20),
 Balance DECIMAL(12,2),
 FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID)
);

CREATE TABLE BankTransaction (
 TransactionID INT PRIMARY KEY,
 AccountID INT,
 TransactionDate DATE,
 TransactionType VARCHAR(20),
 Amount DECIMAL(12,2),
 FOREIGN KEY (AccountID) REFERENCES Account(AccountID)
);

CREATE TABLE Loan (
 LoanID INT PRIMARY KEY,
 CustomerID INT,
 LoanAmount DECIMAL(12,2),
 InterestRate DECIMAL(5,2),
 LoanStatus VARCHAR(20),
 FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID)
);

INSERT INTO Branch VALUES
(1,'Main Branch','Delhi'),
(2,'City Branch','Gurugram'),
(3,'Market Branch','Faridabad');

INSERT INTO Customer VALUES
(101,'Amit Sharma','Male',35,1),
(102,'Neha Verma','Female',29,2),
(103,'Rohit Kumar','Male',42,1),
(104,'Priya Singh','Female',31,3),
(105,'Karan Mehta','Male',25,2);

INSERT INTO Account VALUES
(1001,101,'Savings',50000),
(1002,102,'Current',80000),
(1003,103,'Savings',65000),
(1004,104,'Savings',40000),
(1005,105,'Current',95000);

INSERT INTO BankTransaction VALUES
(1,1001,'2026-01-05','Deposit',10000),
(2,1001,'2026-01-10','Withdrawal',3000),
(3,1002,'2026-01-12','Deposit',20000),
(4,1003,'2026-02-02','Withdrawal',5000),
(5,1004,'2026-02-10','Deposit',15000),
(6,1005,'2026-02-15','Deposit',25000),
(7,1002,'2026-03-01','Withdrawal',8000),
(8,1003,'2026-03-05','Deposit',12000);

INSERT INTO Loan VALUES
(501,101,200000,8.50,'Approved'),
(502,102,150000,9.00,'Approved'),
(503,104,300000,8.75,'Pending'),
(504,105,100000,10.00,'Approved');

SELECT * FROM Branch;
SELECT * FROM Customer;
SELECT * FROM Account;
SELECT * FROM BankTransaction;
SELECT * FROM Loan;

Verification Queries

SELECT COUNT(*) AS TotalCustomers FROM Customer;
SELECT COUNT(*) AS TotalAccounts FROM Account;
SELECT COUNT(*) AS TotalTransactions FROM BankTransaction;

SELECT TransactionType,
       COUNT(*) AS NumberOfTransactions,
       SUM(Amount) AS TotalAmount
FROM BankTransaction
GROUP BY TransactionType;

Expected counts: 3 branches, 5 customers, 5 accounts, 8 transactions and 4 loans. Deposits total 82000 and withdrawals total 16000.

Result: Source tables have been created and populated successfully.


Practical 3: Create a Data Warehouse

Aim

To create and populate a banking data warehouse for historical analysis.

Star Schema

The Star Schema contains a central fact table connected directly to dimension tables.

DimCustomer
DimDate
DimAccount
DimBranch

↓   ↓   ↓   ↓

FactTransaction

Measures: Amount, TransactionCount

Create the Warehouse Tables

CREATE DATABASE IF NOT EXISTS BankingDW;
USE BankingDW;

CREATE TABLE DimCustomer (
 CustomerKey INT AUTO_INCREMENT PRIMARY KEY,
 CustomerID INT,
 CustomerName VARCHAR(100),
 Gender VARCHAR(10),
 Age INT
);

CREATE TABLE DimBranch (
 BranchKey INT AUTO_INCREMENT PRIMARY KEY,
 BranchID INT,
 BranchName VARCHAR(50),
 City VARCHAR(50)
);

CREATE TABLE DimAccount (
 AccountKey INT AUTO_INCREMENT PRIMARY KEY,
 AccountID INT,
 AccountType VARCHAR(20)
);

CREATE TABLE DimDate (
 DateKey INT PRIMARY KEY,
 FullDate DATE,
 DayNumber INT,
 MonthNumber INT,
 MonthName VARCHAR(20),
 QuarterNumber INT,
 YearNumber INT
);

CREATE TABLE FactTransaction (
 FactKey INT AUTO_INCREMENT PRIMARY KEY,
 TransactionID INT,
 CustomerKey INT,
 BranchKey INT,
 AccountKey INT,
 DateKey INT,
 TransactionType VARCHAR(20),
 Amount DECIMAL(12,2),
 TransactionCount INT DEFAULT 1,
 FOREIGN KEY (CustomerKey) REFERENCES DimCustomer(CustomerKey),
 FOREIGN KEY (BranchKey) REFERENCES DimBranch(BranchKey),
 FOREIGN KEY (AccountKey) REFERENCES DimAccount(AccountKey),
 FOREIGN KEY (DateKey) REFERENCES DimDate(DateKey)
);

Populate the Dimension Tables

INSERT INTO BankingDW.DimCustomer
 (CustomerID,CustomerName,Gender,Age)
SELECT CustomerID,CustomerName,Gender,Age
FROM BankingSource.Customer;

INSERT INTO BankingDW.DimBranch
 (BranchID,BranchName,City)
SELECT BranchID,BranchName,City
FROM BankingSource.Branch;

INSERT INTO BankingDW.DimAccount
 (AccountID,AccountType)
SELECT AccountID,AccountType
FROM BankingSource.Account;

INSERT INTO BankingDW.DimDate
 (DateKey,FullDate,DayNumber,MonthNumber,
  MonthName,QuarterNumber,YearNumber)
SELECT DISTINCT
 CAST(DATE_FORMAT(TransactionDate,'%Y%m%d') AS UNSIGNED),
 TransactionDate,
 DAY(TransactionDate),
 MONTH(TransactionDate),
 MONTHNAME(TransactionDate),
 QUARTER(TransactionDate),
 YEAR(TransactionDate)
FROM BankingSource.BankTransaction;

Populate the Fact Table

INSERT INTO BankingDW.FactTransaction
 (TransactionID,CustomerKey,BranchKey,AccountKey,
  DateKey,TransactionType,Amount,TransactionCount)
SELECT
 t.TransactionID,
 dc.CustomerKey,
 db.BranchKey,
 da.AccountKey,
 CAST(DATE_FORMAT(t.TransactionDate,'%Y%m%d') AS UNSIGNED),
 t.TransactionType,
 t.Amount,
 1
FROM BankingSource.BankTransaction t
JOIN BankingSource.Account a ON t.AccountID=a.AccountID
JOIN BankingSource.Customer c ON a.CustomerID=c.CustomerID
JOIN BankingDW.DimCustomer dc ON c.CustomerID=dc.CustomerID
JOIN BankingDW.DimBranch db ON c.BranchID=db.BranchID
JOIN BankingDW.DimAccount da ON a.AccountID=da.AccountID;

Analyze the Warehouse

SELECT b.BranchName,
       SUM(f.Amount) AS TotalTransactionAmount,
       SUM(f.TransactionCount) AS TotalTransactions
FROM BankingDW.FactTransaction f
JOIN BankingDW.DimBranch b ON f.BranchKey=b.BranchKey
GROUP BY b.BranchName
ORDER BY TotalTransactionAmount DESC;

SELECT d.YearNumber,d.MonthName,f.TransactionType,
       SUM(f.Amount) AS TotalAmount,
       COUNT(*) AS NumberOfTransactions
FROM BankingDW.FactTransaction f
JOIN BankingDW.DimDate d ON f.DateKey=d.DateKey
GROUP BY d.YearNumber,d.MonthNumber,d.MonthName,f.TransactionType
ORDER BY d.YearNumber,d.MonthNumber;

SELECT COUNT(*) AS WarehouseFactRows
FROM BankingDW.FactTransaction;

Expected result: The fact table should contain 8 rows. Branch transaction totals are City Branch = 53000, Main Branch = 30000, and Market Branch = 15000.

Result: The banking data warehouse has been created and populated.


Practical 4: Design Star, Snowflake and Fact Constellation Schemas

Aim

To design three multidimensional models for banking data analysis.

A. Star Schema

A Star Schema has one central fact table connected directly to dimension tables. It is easy to understand and suitable for analytical reports.

Structure: FactTransaction connects to DimCustomer, DimBranch, DimAccount and DimDate.

USE BankingDW;

SELECT b.BranchName,
       SUM(f.Amount) AS TotalDeposits
FROM FactTransaction f
JOIN DimBranch b ON f.BranchKey=b.BranchKey
WHERE f.TransactionType='Deposit'
GROUP BY b.BranchName;

B. Snowflake Schema

A Snowflake Schema normalizes dimensions into related tables. For example, branch information can be separated from city information.

CREATE DATABASE IF NOT EXISTS BankingSnowflake;
USE BankingSnowflake;

CREATE TABLE DimCity (
 CityKey INT PRIMARY KEY,
 CityName VARCHAR(50),
 StateName VARCHAR(50)
);

CREATE TABLE DimBranch (
 BranchKey INT PRIMARY KEY,
 BranchID INT,
 BranchName VARCHAR(50),
 CityKey INT,
 FOREIGN KEY (CityKey) REFERENCES DimCity(CityKey)
);

CREATE TABLE DimCustomer (
 CustomerKey INT PRIMARY KEY,
 CustomerID INT,
 CustomerName VARCHAR(100),
 Gender VARCHAR(10),
 Age INT
);

CREATE TABLE DimAccount (
 AccountKey INT PRIMARY KEY,
 AccountID INT,
 AccountType VARCHAR(20)
);

CREATE TABLE DimDate (
 DateKey INT PRIMARY KEY,
 FullDate DATE,
 MonthNumber INT,
 YearNumber INT
);

CREATE TABLE FactTransaction (
 FactKey INT AUTO_INCREMENT PRIMARY KEY,
 TransactionID INT,
 CustomerKey INT,
 BranchKey INT,
 AccountKey INT,
 DateKey INT,
 TransactionType VARCHAR(20),
 Amount DECIMAL(12,2),
 FOREIGN KEY (CustomerKey) REFERENCES DimCustomer(CustomerKey),
 FOREIGN KEY (BranchKey) REFERENCES DimBranch(BranchKey),
 FOREIGN KEY (AccountKey) REFERENCES DimAccount(AccountKey),
 FOREIGN KEY (DateKey) REFERENCES DimDate(DateKey)
);

INSERT INTO DimCity VALUES
(1,'Delhi','Delhi'),
(2,'Gurugram','Haryana'),
(3,'Faridabad','Haryana');

INSERT INTO DimBranch VALUES
(1,1,'Main Branch',1),
(2,2,'City Branch',2),
(3,3,'Market Branch',3);

INSERT INTO DimCustomer
SELECT CustomerKey,CustomerID,CustomerName,Gender,Age
FROM BankingDW.DimCustomer;

INSERT INTO DimAccount
SELECT AccountKey,AccountID,AccountType
FROM BankingDW.DimAccount;

INSERT INTO DimDate
SELECT DateKey,FullDate,MonthNumber,YearNumber
FROM BankingDW.DimDate;

INSERT INTO FactTransaction
 (TransactionID,CustomerKey,BranchKey,AccountKey,
  DateKey,TransactionType,Amount)
SELECT TransactionID,CustomerKey,BranchKey,AccountKey,
       DateKey,TransactionType,Amount
FROM BankingDW.FactTransaction;

Snowflake Query

SELECT city.CityName,b.BranchName,
       SUM(f.Amount) AS TotalAmount
FROM BankingSnowflake.FactTransaction f
JOIN BankingSnowflake.DimBranch b
 ON f.BranchKey=b.BranchKey
JOIN BankingSnowflake.DimCity city
 ON b.CityKey=city.CityKey
GROUP BY city.CityName,b.BranchName;

Advantage: Reduces repeated dimension data. Disadvantage: Requires additional joins.

C. Fact Constellation Schema

A Fact Constellation, or Galaxy Schema, contains multiple fact tables that share dimensions. In banking, FactTransaction analyzes transactions and FactLoan analyzes loans.

DimCustomer
DimBranch

↓     ↓

FactTransaction
FactLoan

Shared dimensions allow related business processes to be analyzed.

Create and Populate the Loan Fact Table

USE BankingDW;

CREATE TABLE FactLoan (
 LoanFactKey INT AUTO_INCREMENT PRIMARY KEY,
 LoanID INT,
 CustomerKey INT,
 BranchKey INT,
 LoanAmount DECIMAL(12,2),
 InterestRate DECIMAL(5,2),
 LoanStatus VARCHAR(20),
 FOREIGN KEY (CustomerKey) REFERENCES DimCustomer(CustomerKey),
 FOREIGN KEY (BranchKey) REFERENCES DimBranch(BranchKey)
);

INSERT INTO FactLoan
 (LoanID,CustomerKey,BranchKey,LoanAmount,InterestRate,LoanStatus)
SELECT l.LoanID,dc.CustomerKey,db.BranchKey,
       l.LoanAmount,l.InterestRate,l.LoanStatus
FROM BankingSource.Loan l
JOIN BankingSource.Customer c ON l.CustomerID=c.CustomerID
JOIN BankingDW.DimCustomer dc ON c.CustomerID=dc.CustomerID
JOIN BankingDW.DimBranch db ON c.BranchID=db.BranchID;

SELECT b.BranchName,
       COUNT(*) AS NumberOfLoans,
       SUM(l.LoanAmount) AS TotalLoanAmount
FROM BankingDW.FactLoan l
JOIN BankingDW.DimBranch b ON l.BranchKey=b.BranchKey
GROUP BY b.BranchName;

Expected loan totals: Main Branch = 200000, City Branch = 250000, Market Branch = 300000.

Comparison of Multidimensional Schemas

FeatureStarSnowflakeFact Constellation
Fact tablesUsually oneUsually one per modelMultiple
DimensionsDirectly linkedNormalizedCan be shared
JoinsFewerMoreDepends on query
UseSimple reportsHierarchical dimensionsMultiple business processes

Result: Star, Snowflake and Fact Constellation schemas have been designed for the banking enterprise.


Practical 5: Install WEKA for Data Mining Applications

Aim

To install WEKA and perform classification, clustering and association rule mining.

What is WEKA?

WEKA stands for Waikato Environment for Knowledge Analysis. It is a machine learning and data mining software package.

Installation Steps

  1. Visit the official WEKA download page.
  2. Download the appropriate Windows installer.
  3. Run the installer and follow the installation instructions.
  4. Install a compatible Java version if required by the selected WEKA package.
  5. Launch WEKA and open Explorer.

Create a Sample Dataset

Open Notepad and save the following as bank_customers.csv. Choose All Files in the Save As dialog.

Age,Income,ExistingLoan,LoanAccepted
Young,Low,Yes,No
Young,Medium,No,Yes
Middle,High,No,Yes
Middle,Medium,Yes,No
Senior,High,No,Yes
Senior,Low,Yes,No
Young,High,No,Yes
Middle,Low,No,No
Senior,Medium,Yes,No
Young,Medium,Yes,No
Middle,High,No,Yes
Senior,High,Yes,No
Young,Low,No,No
Middle,Medium,No,Yes
Senior,Medium,No,Yes

A. Classification using J48

  1. Open WEKA Explorer.
  2. Select Preprocess and click Open file.
  3. Choose bank_customers.csv.
  4. Open the Classify tab.
  5. Click Choose and select trees, then J48.
  6. Select Cross-validation with 5 folds.
  7. Choose LoanAccepted as the class attribute.
  8. Click Start to run the classifier.

WEKA displays a decision tree, predicted classes, evaluation statistics and a confusion matrix. Results depend on the data and settings.

B. Clustering using SimpleKMeans

  1. Load the dataset in WEKA Explorer.
  2. Open the Cluster tab.
  3. Choose SimpleKMeans.
  4. Set the number of clusters to 2.
  5. Click Start.

Clustering groups records with similar characteristics without requiring a target class.

C. Association Rule Mining using Apriori

  1. Load the CSV dataset in WEKA Explorer.
  2. Open the Associate tab.
  3. Choose Apriori if available.
  4. Click Start.

Apriori discovers associations among attributes. For example, a rule may associate an existing loan with loan acceptance patterns. Any rule found in this small illustrative dataset should not be treated as a reliable banking prediction.

Result

WEKA has been installed and can be used to experiment with classification, clustering and association rule mining.


Conclusion

In these five practicals, the banking source database was designed and populated, a data warehouse was created, Star, Snowflake and Fact Constellation models were implemented, and WEKA was introduced for data mining.

Important Notes

  • Execute the SQL scripts in order: Practical 2, Practical 3, and Practical 4.
  • Run each script only once on a fresh database, or reset the sample databases before rerunning insert statements.
  • Execute the source database creation before loading the warehouse dimensions and facts.
  • The sample banking records are fictional and intended only for educational purposes.
  • Capture your own output screenshots from MySQL Workbench and WEKA if your lab record requires them.


Thursday, 17 September 2026

💻 Online C++ Compiler

Write • Compile • Run • Get Output

How to use:
  1. Write your C++ program in the editor.
  2. Enter input in the I/O section if required.
  3. Press the green RUN ▶ button below.
  4. Check the output in Console.
C++ Programming Practice Lab

Wednesday, 2 September 2026

Basic C Programs with Output for Beginners

Introduction to C Programming: 7 Basic C Programs with Output for Beginners

C programming is one of the most popular and powerful programming languages for beginners. It was developed by Dennis Ritchie at Bell Laboratories. C is often called a foundation programming language because many modern programming languages such as C++, Java, and others have been influenced by C.

C programming is widely used in system programming, operating systems, embedded systems, application development, and software development. Learning basic C programs helps students understand important programming concepts such as variables, data types, input and output, operators, expressions, and conditional statements.

📑 C Programs Covered in This Tutorial

  1. Hello World Program in C
  2. Sum of Two Numbers in C
  3. Average of Three Numbers in C
  4. Arithmetic Operations on Two Numbers in C
  5. Simple Interest Program in C
  6. Temperature Conversion Program in C
  7. Maximum of Three Numbers Using Conditional Operator

1. Program to Display Hello Message in C

The following is a simple Hello World program in C. It uses the printf() function to display a message on the screen.

📌 C Program

#include <stdio.h>

int main()
{
    printf("Hello, Welcome to C Programming!");
    
    return 0;
}

💻 Output

Hello, Welcome to C Programming!

2. Program to Find Sum of Two Numbers in C

This C program takes two numbers as input from the user using the scanf() function and calculates their sum using the addition operator +.

📌 C Program

#include <stdio.h>

int main()
{
    int num1, num2, sum;

    printf("Enter first number: ");
    scanf("%d", &num1);

    printf("Enter second number: ");
    scanf("%d", &num2);

    sum = num1 + num2;

    printf("Sum = %d", sum);

    return 0;
}

💻 Sample Output

Enter first number: 10
Enter second number: 20
Sum = 30

3. Program to Find Average of Three Numbers in C

This program accepts three numbers from the user and calculates their average. The float data type is used to store decimal values.

📌 Formula

Average = (Number1 + Number2 + Number3) / 3

📌 C Program

#include <stdio.h>

int main()
{
    float num1, num2, num3, average;

    printf("Enter three numbers: ");
    scanf("%f %f %f", &num1, &num2, &num3);

    average = (num1 + num2 + num3) / 3;

    printf("Average = %.2f", average);

    return 0;
}

💻 Sample Output

Enter three numbers: 10 20 30
Average = 20.00

4. Program to Perform All Four Arithmetic Operations in C

This program performs the four basic arithmetic operations on two numbers: addition, subtraction, multiplication, and division.

📌 Arithmetic Operators Used in C

  • + for Addition
  • - for Subtraction
  • * for Multiplication
  • / for Division

📌 C Program

#include <stdio.h>

int main()
{
    float num1, num2;

    printf("Enter two numbers: ");
    scanf("%f %f", &num1, &num2);

    printf("\nAddition = %.2f", num1 + num2);
    printf("\nSubtraction = %.2f", num1 - num2);
    printf("\nMultiplication = %.2f", num1 * num2);

    if(num2 != 0)
        printf("\nDivision = %.2f", num1 / num2);
    else
        printf("\nDivision is not possible because divisor is zero.");

    return 0;
}

💻 Sample Output

Enter two numbers: 20 5

Addition = 25.00
Subtraction = 15.00
Multiplication = 100.00
Division = 4.00

5. Program to Find Simple Interest in C

This C program calculates simple interest by taking the principal amount, rate of interest, and time from the user.

📌 Simple Interest Formula

Simple Interest = (Principal × Rate × Time) / 100

📌 C Program

#include <stdio.h>

int main()
{
    float principal, rate, time, simpleInterest;

    printf("Enter Principal Amount: ");
    scanf("%f", &principal);

    printf("Enter Rate of Interest: ");
    scanf("%f", &rate);

    printf("Enter Time in Years: ");
    scanf("%f", &time);

    simpleInterest = (principal * rate * time) / 100;

    printf("Simple Interest = %.2f", simpleInterest);

    return 0;
}

💻 Sample Output

Enter Principal Amount: 10000
Enter Rate of Interest: 5
Enter Time in Years: 2

Simple Interest = 1000.00

6. Program for Temperature Conversion in C

This program converts temperature from Celsius to Fahrenheit.

📌 Temperature Conversion Formula

Fahrenheit = (Celsius × 9 / 5) + 32

📌 C Program

#include <stdio.h>

int main()
{
    float celsius, fahrenheit;

    printf("Enter temperature in Celsius: ");
    scanf("%f", &celsius);

    fahrenheit = (celsius * 9 / 5) + 32;

    printf("Temperature in Fahrenheit = %.2f", fahrenheit);

    return 0;
}

💻 Sample Output

Enter temperature in Celsius: 25

Temperature in Fahrenheit = 77.00

7. Program to Find Maximum of Three Numbers Using Conditional Operator in C

This program finds the largest number among three numbers using the conditional operator. The conditional operator ? : is also known as the ternary operator in C programming.

📌 Syntax of Conditional Operator

condition ? expression1 : expression2;

📌 C Program

#include <stdio.h>

int main()
{
    int a, b, c, max;

    printf("Enter three numbers: ");
    scanf("%d %d %d", &a, &b, &c);

    max = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);

    printf("Maximum number = %d", max);

    return 0;
}

💻 Sample Output

Enter three numbers: 10 25 18

Maximum number = 25

📚 Summary of Basic C Programs

These basic C programs are useful for beginners who are learning C programming and preparing for programming practicals, assignments, viva questions, and coding practice.

Program No. C Program Name
1 Hello World Program in C
2 Sum of Two Numbers in C
3 Average of Three Numbers in C
4 Four Arithmetic Operations in C
5 Simple Interest Program in C
6 Temperature Conversion Program in C
7 Maximum of Three Numbers Using Conditional Operator in C

Program to Calculate the Area of a Circle

Aim

To write a C program to calculate the area of a circle.

Formula

Area of Circle = π × r × r

Where r is the radius of the circle and π = 3.14159.

C Program

#include <stdio.h>

int main()
{
    float radius, area;

    printf("Enter the radius of the circle: ");
    scanf("%f", &radius);

    area = 3.14159 * radius * radius;

    printf("Area of the circle = %.2f", area);

    return 0;
}

Sample Output

Enter the radius of the circle: 5
Area of the circle = 78.54

Online Area of Circle Calculator

Enter the radius below to calculate the area of the circle:




Example

If the radius of the circle is 5 units:

Area = π × r × r
= 3.14159 × 5 × 5
= 78.54 square units

C Program to Find Square Root Without Using sqrt() Function

In this C program, we will learn how to find the square root of a number without using the built-in sqrt() function. This is useful for beginners to understand how a square root can be calculated using a simple loop and approximation.

What is a Square Root?

The square root of a number is a value which, when multiplied by itself, gives the original number.

Example:

5 × 5 = 25
Therefore, √25 = 5

C Program

The following program finds the square root approximately without using sqrt().

#include <stdio.h>

int main()
{
    float num, i;

    printf("Enter a number: ");
    scanf("%f", &num);

    i = 0;

    while (i * i <= num)
    {
        i = i + 0.01;
    }

    printf("Square root of %.2f is approximately %.2f", num, i);

    return 0;
}

How Does the Program Work?

Suppose the user enters:

25

Initially:

i = 0

The while loop checks whether:

i * i <= num

The value of i is gradually increased:

0.00
0.01
0.02
0.03
...
4.98
4.99
5.00

When i = 5:

5 × 5 = 25

Therefore, the square root is approximately 5.

What Does i = i + 0.01 Mean?

The statement:

i = i + 0.01;

means that 0.01 is added to the current value of i each time the loop runs.

For example:

i = 0
i = 0.01
i = 0.02
i = 0.03
...
i = 4.99
i = 5.00

What If We Use i = i + 0.1?

We can also write:

i = i + 0.1;

In this case, the value increases by 0.1 each time:

0
0.1
0.2
0.3
0.4
...
4.8
4.9
5.0

This makes the program faster because fewer iterations are required, but the answer is less precise.

0.1 vs 0.01

Increment Accuracy Speed
i = i + 1 Low Fast
i = i + 0.1 About 1 decimal place Faster
i = i + 0.01 About 2 decimal places Slower
i = i + 0.001 About 3 decimal places More iterations

Example Output

Enter a number: 25
Square root of 25.00 is approximately 5.01

The result may show 5.01 because the loop stops after the value becomes slightly greater than the actual square root.

Key Points

  • No sqrt() function is used.
  • The program uses a while loop.
  • i * i is used to check the square of the current value.
  • i = i + 0.01 gradually increases the value of i.
  • A smaller increment provides better approximation but requires more iterations.

Conclusion

This simple C program demonstrates how a square root can be approximated without using the built-in sqrt() function. It is a good beginner example for understanding loops, floating-point numbers, conditions, and approximation.

C Program to Calculate Electricity Bill

In this C program, we will learn how to calculate an electricity bill based on the number of units consumed. The program uses if-else conditions to apply different rates for different ranges of electricity consumption.

What is an Electricity Bill?

An electricity bill is generally calculated according to the number of electricity units consumed. Different unit ranges may have different rates.

For this example, we will use the following rates:

Units Consumed Rate per Unit
0 – 100 units ₹5
101 – 200 units ₹7
201 – 300 units ₹10
Above 300 units ₹12

These rates are used only for learning the C programming concept. Actual electricity tariffs vary by electricity provider and consumer category.

C Program

#include <stdio.h>

int main()
{
    int units;
    float bill;

    printf("Enter electricity units consumed: ");
    scanf("%d", &units);

    if (units <= 100)
    {
        bill = units * 5;
    }
    else if (units <= 200)
    {
        bill = (100 * 5) + ((units - 100) * 7);
    }
    else if (units <= 300)
    {
        bill = (100 * 5) + (100 * 7) + ((units - 200) * 10);
    }
    else
    {
        bill = (100 * 5) + (100 * 7) + (100 * 10)
             + ((units - 300) * 12);
    }

    printf("Electricity Bill = Rs. %.2f", bill);

    return 0;
}

How Does the Program Work?

First, the program asks the user to enter the number of electricity units consumed.

Enter electricity units consumed: 250

The program then checks the number of units using if-else if-else statements.

Example: 250 Units

Suppose the consumer has used 250 units.

The calculation will be:

First 100 units:
100 × ₹5 = ₹500

Next 100 units:
100 × ₹7 = ₹700

Remaining 50 units:
50 × ₹10 = ₹500

Total Bill:
₹500 + ₹700 + ₹500 = ₹1700

Example Output

Enter electricity units consumed: 250
Electricity Bill = Rs. 1700.00

Understanding the Condition

The first condition checks whether the units are less than or equal to 100:

if (units <= 100)
{
    bill = units * 5;
}

If the units are between 101 and 200, the first 100 units are charged at ₹5 and the remaining units are charged at ₹7.

bill = (100 * 5) + ((units - 100) * 7);

Similarly, for units between 201 and 300, the program calculates the charges for the first 100 units, the next 100 units, and then the remaining units separately.

Why Do We Use (units - 100)?

Suppose the user enters 150 units.

The first 100 units are already charged at ₹5. Therefore, only the remaining 50 units need to be charged at ₹7.

150 - 100 = 50

Therefore:

100 × ₹5 = ₹500
50 × ₹7  = ₹350

Total = ₹850

Key Points

  • The program takes electricity consumption in units as input.
  • if-else if-else is used to select the appropriate slab.
  • Each electricity slab has a different rate.
  • The bill is calculated progressively for higher unit consumption.
  • %.2f displays the bill with two digits after the decimal point.

Conclusion

This C program is a useful beginner example for understanding if-else conditions, arithmetic operators, user input, and slab-based calculations. Similar logic can be used in programs for calculating water bills, telephone bills, income tax, and other charges.

C Program to Print Numbers from 1 to N Using While Loop

In this C program, we will take a number N from the user and print all the numbers from 1 to N using a while loop.

C Program

#include <stdio.h>

int main()
{
    int n, i = 1;

    printf("Enter the value of n: ");
    scanf("%d", &n);

    while (i <= n)
    {
        printf("%d ", i);
        i++;
    }

    return 0;
}

How the Program Works

  1. The user enters the value of n.
  2. The variable i is initialized to 1.
  3. The while loop checks whether i <= n.
  4. If the condition is true, the value of i is printed.
  5. The statement i++ increases the value of i by 1.
  6. The loop continues until i becomes greater than n.

Sample Output

Enter the value of n: 10
1 2 3 4 5 6 7 8 9 10

Dry Run

i Condition (i <= n) Output i++
1 1 <= 10 → True 1 2
2 2 <= 10 → True 2 3
3 3 <= 10 → True 3 4
... ... ... ...
10 10 <= 10 → True 10 11
11 11 <= 10 → False Loop stops -

Important Points

  • while is an entry-controlled loop.
  • The loop condition is checked before executing the loop body.
  • i++ is necessary; otherwise, the loop may become an infinite loop.
  • The program prints numbers starting from 1 up to the value entered by the user.

Conclusion

This is a simple example of using a while loop in C. It is useful for understanding initialization, condition checking, and incrementing a loop variable.

🎯 Practice is the Key to Learning C Programming!

These basic C programs help beginners understand important concepts such as input and output, variables, arithmetic operators, conditional operators, and mathematical calculations in C programming. Try changing the input values and experiment with these programs to improve your programming skills.

C If-Else Programs with Examples and Output

The if-else statement is used in C programming to make decisions. It checks a condition and executes a particular block of code depending on whether the condition is true or false.

1. Check Whether Age is Greater Than 18 Using if-else

This program takes the age of a person and checks whether the person is greater than 18 years old.

#include <stdio.h>

int main()
{
    int age;

    printf("Enter your age: ");
    scanf("%d", &age);

    if (age > 18)
    {
        printf("You are greater than 18 years old.");
    }
    else
    {
        printf("You are 18 years old or younger.");
    }

    return 0;
}

Output

Enter your age: 21
You are greater than 18 years old.

2. Check Positive, Negative or Zero Using Nested if-else

A nested if-else means using one if-else statement inside another if-else statement.

#include <stdio.h>

int main()
{
    int num;

    printf("Enter a number: ");
    scanf("%d", &num);

    if (num >= 0)
    {
        if (num == 0)
        {
            printf("The number is zero.");
        }
        else
        {
            printf("The number is positive.");
        }
    }
    else
    {
        printf("The number is negative.");
    }

    return 0;
}

Output 1

Enter a number: 15
The number is positive.

Output 2

Enter a number: -8
The number is negative.

Output 3

Enter a number: 0
The number is zero.

3. Grade Checking Using else-if

The else-if ladder is useful when we have multiple conditions to check. The following program displays a grade according to the marks obtained.

#include <stdio.h>

int main()
{
    int marks;

    printf("Enter your marks: ");
    scanf("%d", &marks);

    if (marks >= 90)
    {
        printf("Grade A");
    }
    else if (marks >= 80)
    {
        printf("Grade B");
    }
    else if (marks >= 70)
    {
        printf("Grade C");
    }
    else if (marks >= 60)
    {
        printf("Grade D");
    }
    else if (marks >= 40)
    {
        printf("Grade E");
    }
    else
    {
        printf("Fail");
    }

    return 0;
}

Output

Enter your marks: 85
Grade B

4. Double Condition Using && (AND Operator)

The && operator is called the logical AND operator. Both conditions must be true for the complete condition to be true.

Example: A student is eligible for admission if the marks are 50 or more and the age is 18 or more.

#include <stdio.h>

int main()
{
    int marks, age;

    printf("Enter your marks: ");
    scanf("%d", &marks);

    printf("Enter your age: ");
    scanf("%d", &age);

    if (marks >= 50 && age >= 18)
    {
        printf("You are eligible.");
    }
    else
    {
        printf("You are not eligible.");
    }

    return 0;
}

Output

Enter your marks: 65
Enter your age: 20
You are eligible.

5. Double Condition Using || (OR Operator)

The || operator is called the logical OR operator. If at least one of the conditions is true, the complete condition becomes true.

Example: A student can participate if they have a valid ID card or a valid registration number.

#include <stdio.h>

int main()
{
    int id, registration;

    printf("Enter ID card status (1 for Yes, 0 for No): ");
    scanf("%d", &id);

    printf("Enter registration status (1 for Yes, 0 for No): ");
    scanf("%d", &registration);

    if (id == 1 || registration == 1)
    {
        printf("You can participate.");
    }
    else
    {
        printf("You cannot participate.");
    }

    return 0;
}

Output

Enter ID card status (1 for Yes, 0 for No): 0
Enter registration status (1 for Yes, 0 for No): 1
You can participate.

Summary

Concept Purpose
if-else Checks one condition and chooses between two alternatives.
Nested if-else Places an if-else statement inside another if-else statement.
else-if Checks multiple conditions one after another.
&& AND – both conditions must be true.
|| OR – at least one condition must be true.

1. Star Right-Angled Pyramid

C Program

#include <stdio.h>

int main()
{
    int i, j, n;

    printf("Enter number of rows: ");
    scanf("%d", &n);

    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= i; j++)
        {
            printf("* ");
        }
        printf("\n");
    }

    return 0;
}

Output

Enter number of rows: 5

*
* *
* * *
* * * *
* * * * *

2. Inverted Star Pyramid

C Program

#include <stdio.h>

int main()
{
    int i, j, n;

    printf("Enter number of rows: ");
    scanf("%d", &n);

    for(i = n; i >= 1; i--)
    {
        for(j = 1; j <= i; j++)
        {
            printf("* ");
        }
        printf("\n");
    }

    return 0;
}

Output

Enter number of rows: 5

* * * * *
* * * *
* * *
* *
*

3. Number Pyramid

C Program

#include <stdio.h>

int main()
{
    int i, j, n;

    printf("Enter number of rows: ");
    scanf("%d", &n);

    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= i; j++)
        {
            printf("%d ", j);
        }
        printf("\n");
    }

    return 0;
}

Output

Enter number of rows: 5

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

These examples are useful for beginners learning decision-making statements in C programming.

4. Centered Star Pyramid

C Program

#include <stdio.h>

int main()
{
    int i, j, n;

    printf("Enter number of rows: ");
    scanf("%d", &n);

    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= n - i; j++)
        {
            printf(" ");
        }

        for(j = 1; j <= 2 * i - 1; j++)
        {
            printf("*");
        }

        printf("\n");
    }

    return 0;
}

Output

Enter number of rows: 5

    *
   ***
  *****
 *******
*********
Row 1 → " " Row 2 → " " Row 3 → " " Row 4 → " " Row 5 → ""8 Row 1 → 1 star Row 2 → 3 stars Row 3 → 5 stars Row 4 → 7 stars Row 5 → 9 stars Row 1: 4 spaces + 1 star * Row 2: 3 spaces + 3 stars *** Row 3: 2 spaces + 5 stars ***** Row 4: 1 space + 7 stars ******* Row 5: 0 spaces + 9 stars *********

5. Number Palindrome Pyramid

C Program

#include <stdio.h>

int main()
{
    int i, j, n;

    printf("Enter number of rows: ");
    scanf("%d", &n);

    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= n - i; j++)
        {
            printf(" ");
        }

        for(j = i; j >= 1; j--)
        {
            printf("%d", j);
        }

        for(j = 2; j <= i; j++)
        {
            printf("%d", j);
        }

        printf("\n");
    }

    return 0;
}

Output

Enter number of rows: 5

    1
   121
  12321
 1234321
123454321
```html

Switch Case in C Programming

The switch-case statement in C is used to select one option from multiple choices. It is useful when a program has several fixed choices.

Syntax of Switch Case

switch(expression)
{
    case value1:
        // statements
        break;

    case value2:
        // statements
        break;

    default:
        // statements
}

Program 1: Display Day Using Switch Case

Question: Write a C program to enter a number from 1 to 7 and display the corresponding day of the week using switch-case.

Solution

#include <stdio.h>

int main()
{
    int day;

    printf("Enter day number (1-7): ");
    scanf("%d", &day);

    switch(day)
    {
        case 1:
            printf("Monday");
            break;

        case 2:
            printf("Tuesday");
            break;

        case 3:
            printf("Wednesday");
            break;

        case 4:
            printf("Thursday");
            break;

        case 5:
            printf("Friday");
            break;

        case 6:
            printf("Saturday");
            break;

        case 7:
            printf("Sunday");
            break;

        default:
            printf("Invalid day number");
    }

    return 0;
}

Output

Enter day number (1-7): 3
Wednesday

Program 2: Simple Calculator Using Switch Case

Question: Write a C program to perform addition, subtraction, multiplication, or division using switch-case.

Solution

#include <stdio.h>

int main()
{
    float a, b;
    char op;

    printf("Enter first number: ");
    scanf("%f", &a);

    printf("Enter operator (+, -, *, /): ");
    scanf(" %c", &op);

    printf("Enter second number: ");
    scanf("%f", &b);

    switch(op)
    {
        case '+':
            printf("Result = %.2f", a + b);
            break;

        case '-':
            printf("Result = %.2f", a - b);
            break;

        case '*':
            printf("Result = %.2f", a * b);
            break;

        case '/':
            if(b != 0)
            {
                printf("Result = %.2f", a / b);
            }
            else
            {
                printf("Division by zero is not possible");
            }
            break;

        default:
            printf("Invalid operator");
    }

    return 0;
}

Output

Enter first number: 20
Enter operator (+, -, *, /): *
Enter second number: 5
Result = 100.00

Important Point: break Statement

The break statement is used to stop the execution of the switch after the matching case is executed.

If break is missing, the program may continue executing the next cases. This is called fall-through.

Example Without break

switch(choice)
{
    case 1:
        printf("One");

    case 2:
        printf("Two");

    case 3:
        printf("Three");
}

If the value of choice is 1, the output can be:

One
Two
Three

Therefore, break is normally used after each case.

```

Friday, 6 March 2026

CSS HTML Examples With Code

 

1. Super Market Web Page using Internal CSS

<!DOCTYPE html>
<html>
<head>
<title>Super Market</title>

<style>
body{
font-family: Arial;
background-color: #f2f2f2;
}

h1{
color: white;
background-color: green;
text-align: center;
padding: 10px;
}

.container{
width: 80%;
margin: auto;
}

.product{
background-color: white;
padding: 10px;
margin: 10px;
border: 1px solid gray;
}

</style>

</head>

<body>

<h1>Fresh Super Market</h1>

<div class="container">

<div class="product">
<h3>Rice</h3>
<p>Price: ₹60 per kg</p>
</div>

<div class="product">
<h3>Milk</h3>
<p>Price: ₹50 per litre</p>
</div>

<div class="product">
<h3>Bread</h3>
<p>Price: ₹30</p>
</div>

<div class="product">
<h3>Apples</h3>
<p>Price: ₹120 per kg</p>
</div>

<div class="product">
<h3>Eggs</h3>
<p>Price: ₹6 per egg</p>
</div>

</div>

</body>
</html>

2. Resume using Inline CSS

<!DOCTYPE html>
<html>
<head>
<title>My Resume</title>
</head>

<body style="font-family: Arial; background-color: #f4f4f4;">

<h1 style="color: blue;">Manisha Bhardwaj</h1>

<p style="font-size:18px;">Email: manisha@email.com</p>
<p style="font-size:18px;">Phone: 9876543210</p>

<h2 style="color: green;">Career Objective</h2>
<p style="font-size:16px;">To work in a challenging environment where I can use my skills and knowledge.</p>

<h2 style="color: green;">Education</h2>
<ul style="font-size:16px;">
<li>B.Tech / MCA</li>
<li>12th from CBSE</li>
<li>10th from CBSE</li>
</ul>

<h2 style="color: green;">Skills</h2>
<ul style="font-size:16px;">
<li>HTML</li>
<li>CSS</li>
<li>Python</li>
</ul>

<h2 style="color: green;">Hobbies</h2>
<ul style="font-size:16px;">
<li>Reading</li>
<li>Music</li>
<li>Traveling</li>
</ul>

</body>
</html>

Friday, 20 February 2026

CSS and type of CSS

1. Inline CSS (The "Direct Note")This is written directly inside the HTML tag. 
It’s like putting a sticker right on an object.Best for: Changing just one specific thing very quickly.Example:
HTML

I am Blue!

2. Internal CSS (The "Instruction List")This is written at the top of your HTML file inside a 





3. External CSS (The "Separate Book")This is the most professional way. 
You create a completely separate file (ending in .css) and link it to your HTML.
Best for: 
Big websites with many pages. 
You can change the color of 100 pages at once just by changing one line in the CSS file!
Example:In your HTML: In your style.css file: body { background-color: lightgreen; }


EXAMPLE OF CSS AND HTML

Project Name: The Season Watcher 3000

The Real-Life Question: "How can we create a dashboard that shows the current season, but makes it look like a high-tech app where the buttons glow and the boxes pop out when you touch them?"




The HTML File (index.html)

This is the Structure. We are creating a "Container" to hold our four "Season Cards."

HTML
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Season Watcher 3000</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>

    <h1 class="main-title">Smart Home: Season Monitor</h1>

    <div class="dashboard">
        <div class="card" id="spring">
            <div class="icon">🌸</div>
            <h2>Spring</h2>
            <p>Status: Blooming</p>
            <button class="btn">View Garden</button>
        </div>

        <div class="card" id="summer">
            <div class="icon">☀️</div>
            <h2>Summer</h2>
            <p>Status: Sunny</p>
            <button class="btn">Check AC</button>
        </div>

        <div class="card" id="autumn">
            <div class="icon">🍂</div>
            <h2>Autumn</h2>
            <p>Status: Windy</p>
            <button class="btn">Clear Leaves</button>
        </div>

        <div class="card" id="winter">
            <div class="icon">❄️</div>
            <h2>Winter</h2>
            <p>Status: Freezing</p>
            <button class="btn">Heat On</button>
        </div>
    </div>

</body>
</html>

2. The External CSS File (style.css)

This is the Style. We use "Flexbox" to align the boxes and "Transitions" to make them move smoothly.

CSS
/* General Page Setup */
body {
    background-color: #1a1a2e; /* Dark "Space" Blue */
    color: white;
    font-family: 'Segoe UI', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 50px;
}

.main-title {
    margin-bottom: 40px;
    text-transform: uppercase;
    letter-spacing: 3px;
    border-bottom: 2px solid #0f3460;
}

/* The Grid/Dashboard Layout */
.dashboard {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Designing the Individual Cards */
.card {
    background-color: #16213e;
    border: 2px solid #0f3460;
    border-radius: 20px;
    padding: 30px;
    width: 200px;
    text-align: center;
    /* This makes the animation smooth! */
    transition: all 0.4s ease;
}

/* Real-Life Interaction: The Hover Effect */
.card:hover {
    transform: scale(1.1) rotate(2deg); /* Grows and tilts slightly */
    border-color: #e94560;
    box-shadow: 0px 10px 30px rgba(233, 69, 96, 0.5);
}

.icon {
    font-size: 50px;
    margin-bottom: 10px;
}

/* Making the Buttons Glow */
.btn {
    background-color: #e94560;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 50px;
    cursor: pointer;
    font-weight: bold;
    margin-top: 15px;
}

.btn:hover {
    background-color: white;
    color: #e94560;
}

What makes this a "Good" Demo?

  1. The "Pop" (Scale): In the CSS, transform: scale(1.1) makes the card grow when you touch it with the mouse. This feels like a modern app.

  2. The "Glow" (Box-Shadow): Using box-shadow on hover makes the card look like it’s lighting up.

  3. Flexbox: The display: flex command in the .dashboard section acts like a magnet, pulling all the cards into a neat line automatically.

Thursday, 19 February 2026

HTML CODE FOR DISPLAYING 4 DIFFERENT HTML PAGES ON SINGLE HTML PAGE USING FRAMES

To display four separate HTML files on a single page using a "frames" approach, we use the tag. This is the classic way to split a browser window into multiple independent sections. Since replaces the tag, this "Master" file will pull the content from four other files you create. 1. The Master File (index.html) This file defines the layout. It creates two rows and two columns. The Four Seasons - Master Frame <body> Your browser does not support frames. Please update your browser. </body> HTML 

  The Four Seasons - Master Frame <body> Your browser does not support frames. Please update your browser. </body> 2. The Four Content Files You must create these four files and save them in the same folder as your index.html. 
<frameset cols="50%,50%" rows="50%,50%">
    <frame name="springFrame" noresize="" scrolling="yes" src="spring.html">
    <frame name="summerFrame" noresize="" scrolling="yes" src="summer.html">
    <frame name="autumnFrame" noresize="" scrolling="yes" src="autumn.html">
    <frame name="winterFrame" noresize="" scrolling="yes" src="winter.html">
    
    <noframes>
        <body>
            Your browser does not support frames. Please update your browser.
        </body>
    </noframes>
</frame></frame></frame></frame></frameset>

 File 1: spring.html HTML 

Spring Season

Spring is a time of rebirth. Flowers bloom and the weather turns mild.

File 2: summer.html HTML 

Summer Season

Summer is the hottest season. It is perfect for vacations and swimming.

File 3: autumn.html HTML 

Autumn Season

In Autumn, leaves change color to gold and red before falling.

File 4: winter.html HTML 

Winter Season

Winter brings snow and ice. It is the coldest time of the year.

How to run this: Create a folder on your computer. 
 Save the first block of code as index.html.
 Save the four season codes as spring.html, summer.html, autumn.html, and winter.html. 
 Open index.html with your browser. 
 Key Attributes Used: rows="50%,50%":
 Splits the screen horizontally into two equal halves. cols="50%,50%": 
Splits the screen vertically into two equal halves. 
 noresize: Prevents the user from dragging the borders to change frame sizes.
 scrolling="yes": Adds a scrollbar if your content or image is too large for the frame.

Dataware housing and data mining

Data Warehousing and Data Mining Lab Practicals Enterprise: Banking Management System Software: MySQL 8.0, MySQL Workbench and WEKA ...