Skip to content

PROG SKILL (204) Set C - Practical Solutions

Paper Information

Attribute Value
Subject Programming Skills Using C
Subject Code 204 (PROG SKILL)
Set C
Exam Type Practical
Max Marks 25
Month/Year April 2024

Question 1: Employee Structure with Salary Calculation

Question 1: Create Structure and Calculate Net Salary

Q: Write a C program to create a structure employee with a member employee I'd, employee name and basic salary. Read employee information from user and calculate net salary where net salary = basic salary + HRA + DA - PF. HRA is 10% of basic salary, DA is 50% of basic salary and PF is 20% of basic salary.

Requirements: - Create structure with: employee_id, employee_name, basic_salary - Read employee information from user - Calculate HRA = 10% of basic salary - Calculate DA = 50% of basic salary - Calculate PF = 20% of basic salary - Calculate Net Salary = Basic + HRA + DA - PF - Display all information in proper format

Solution - C Language
#include <stdio.h>
#include <string.h>

// Define structure for employee
struct Employee {
    int employee_id;
    char employee_name[50];
    float basic_salary;
    float hra;
    float da;
    float pf;
    float net_salary;
};

int main() {
    struct Employee emp;

    // Input employee information
    printf("Enter Employee Details:\n\n");

    printf("Enter Employee ID: ");
    scanf("%d", &emp.employee_id);

    printf("Enter Employee Name: ");
    scanf(" %[^\n]", emp.employee_name);

    printf("Enter Basic Salary: ");
    scanf("%f", &emp.basic_salary);

    // Calculate salary components
    emp.hra = emp.basic_salary * 0.10;    // 10% of basic
    emp.da = emp.basic_salary * 0.50;     // 50% of basic
    emp.pf = emp.basic_salary * 0.20;     // 20% of basic

    // Calculate net salary
    emp.net_salary = emp.basic_salary + emp.hra + emp.da - emp.pf;

    // Display salary slip
    printf("\n========================================\n");
    printf("         SALARY SLIP\n");
    printf("========================================\n\n");

    printf("Employee ID:    %d\n", emp.employee_id);
    printf("Employee Name:  %s\n", emp.employee_name);
    printf("----------------------------------------\n");
    printf("Basic Salary:   %.2f\n", emp.basic_salary);
    printf("HRA (10%%):      +%.2f\n", emp.hra);
    printf("DA (50%%):       +%.2f\n", emp.da);
    printf("PF (20%%):       -%.2f\n", emp.pf);
    printf("----------------------------------------\n");
    printf("Net Salary:     %.2f\n", emp.net_salary);
    printf("========================================\n");

    return 0;
}
Expected Output - C
Enter Employee Details:

Enter Employee ID: 101
Enter Employee Name: Rahul Sharma
Enter Basic Salary: 50000

========================================
         SALARY SLIP
========================================

Employee ID:    101
Employee Name:  Rahul Sharma
----------------------------------------
Basic Salary:   50000.00
HRA (10%):      +5000.00
DA (50%):       +25000.00
PF (20%):       -10000.00
----------------------------------------
Net Salary:     70000.00
========================================
Solution - Python
# Employee salary calculation

# Input employee information
print("Enter Employee Details:\n")

employee_id = int(input("Enter Employee ID: "))
employee_name = input("Enter Employee Name: ")
basic_salary = float(input("Enter Basic Salary: "))

# Calculate salary components
hra = basic_salary * 0.10      # 10% of basic
da = basic_salary * 0.50       # 50% of basic
pf = basic_salary * 0.20       # 20% of basic

# Calculate net salary
net_salary = basic_salary + hra + da - pf

# Display salary slip
print("\n" + "=" * 50)
print("         SALARY SLIP")
print("=" * 50 + "\n")

print(f"Employee ID:    {employee_id}")
print(f"Employee Name:  {employee_name}")
print("-" * 50)
print(f"Basic Salary:   {basic_salary:.2f}")
print(f"HRA (10%):      +{hra:.2f}")
print(f"DA (50%):       +{da:.2f}")
print(f"PF (20%):       -{pf:.2f}")
print("-" * 50)
print(f"Net Salary:     {net_salary:.2f}")
print("=" * 50)
Expected Output - Python
Enter Employee Details:

Enter Employee ID: 101
Enter Employee Name: Rahul Sharma
Enter Basic Salary: 50000

==================================================
         SALARY SLIP
==================================================

Employee ID:    101
Employee Name:  Rahul Sharma
--------------------------------------------------
Basic Salary:   50000.00
HRA (10%):      +5000.00
DA (50%):       +25000.00
PF (20%):       -10000.00
--------------------------------------------------
Net Salary:     70000.00
==================================================
Explanation

Salary Calculation Breakdown: - Basic Salary: Base amount entered by user - HRA (House Rent Allowance): 10% of basic = basic × 0.10 - DA (Dearness Allowance): 50% of basic = basic × 0.50 - PF (Provident Fund): 20% of basic = basic × 0.20 (deduction) - Net Salary: basic + hra + da - pf

Example with 50,000 basic: - HRA = 5,000, DA = 25,000, PF = 10,000 - Net = 50,000 + 5,000 + 25,000 - 10,000 = 70,000

Concept Deep Dive: Salary Components

Understanding Payroll: - Gross Salary: Basic + All allowances (HRA, DA, etc.) - Deductions: PF, Professional Tax, Income Tax - Net Salary: Gross - Deductions (take-home pay) - Structure organizes all components systematically


Question 2: Viva Preparation

Question 2: Viva + Journal

Q: Viva + Journal (5 Marks)

Potential Viva Questions

Q1: Why use a structure instead of separate variables? - A: Structure groups related employee data logically, reduces variable clutter, enables array of employees, and makes code maintainable.

Q2: Explain the calculation formula for net salary. - A: Net = Basic + HRA + DA - PF. Here HRA is 10%, DA is 50% (positive additions), PF is 20% (deduction from total).

Q3: What happens if we use integer instead of float for salary? - A: Decimal precision is lost (e.g., 5000.50 becomes 5000). Float ensures accurate calculation of percentages.

Q4: Can this program handle multiple employees? - A: Yes, by creating an array of structures: struct Employee emp[10]; and using loops for input/output.

Q5: What is the purpose of scanf(" %[^\n]", ...) for name input? - A: It reads a string with spaces (full name) until newline. The leading space skips any leftover whitespace.

Common Pitfalls

  • Percentage calculation: Use 0.10 not 10 for 10%
  • Float format specifier: Use %f or %.2f not %d
  • PF deduction: Remember to subtract PF, not add
  • Input buffer: Leading space in " %[^\n]" prevents reading issues
  • Precision: Use %.2f to display currency with 2 decimal places

Set Link
Set A Solutions
Set B Solutions
Set C Current Page
Set D Coming Soon
Set E Coming Soon
Set F Coming Soon

Quick Navigation