0% found this document useful (0 votes)
34 views

Ex 3 - DSCP Lab

The document describes a C program to calculate employee payroll using structures. It defines a structure called "emp" with fields for employee number, name, basic pay, allowances, deductions, and net pay. The program gets employee details from the user in a for loop, calculates net pay as basic pay plus allowances minus deductions, and prints the results. The aim of writing this program using structures was achieved successfully.

Uploaded by

Dr. M.Kamarajan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Ex 3 - DSCP Lab

The document describes a C program to calculate employee payroll using structures. It defines a structure called "emp" with fields for employee number, name, basic pay, allowances, deductions, and net pay. The program gets employee details from the user in a for loop, calculates net pay as basic pay plus allowances minus deductions, and prints the results. The aim of writing this program using structures was achieved successfully.

Uploaded by

Dr. M.Kamarajan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

EX.

NO : 3A SWAP TWO VARIABLES USING FUNCTIONS


DATE :

AIM:
Write a C program to swap two integers using call by value and call by
reference methods of passing arguments to a function.

ALGORITHM:
1. Start the program.
2. Set a ← 1, b ← 2, c ← 3, and d ← 4
3. Call the function swap_call_by_val (a, b)
4. Start function.
a. Assign temp ← a
b. Assign a ← b
c. Assign b ← temp
d. Print a and b.
e. End function.
5. Call the function swap_call_by_ref (*c, *d)
6. Start function.
a. Assign temp ← *c
b. Assign *c ← *d
c. Assign *d ← temp
d. Print c and d.
e. End function.
7. Stop the program.

PROGRAM:
/* Swap two integers using call by value and call by reference methods */
#include <stdio.h>
void swap_call_by_val (int, int);
void swap_call_by_ref (int *, int *);
int main ()
{
int a = 1, b = 2, c = 3, d = 4;
printf (“\n In main (), a = %d and b = %d”, a, b);
swap_call_by_val (a, b);
printf (“\n In main (), a = %d and b = %d”, a, b);
printf (“\n In main (), c = %d and d = %d”, c, d);
swap_call_by_ref (&c, &d);
printf (“\n In main (), c = %d and d = %d”, c, d);
return 0;
}

void swap_call_by_val (int a, int b)


{
int temp;
temp = a ;

1
a = b;
b = temp;
printf (“\n In function (Call By Value Method) a = %d and b = %d”, a,b);
}

void swap_call_by_ref (int *c, int *d)


{
int temp;
temp = *c;
*c = *d;
*d = temp;
printf (“\n In function (Call By Reference Method) c = %d and d = %d”, *c, *d);
}
OUTPUT:
In main (), a = 1 and b= 2
In function (Call By Value Method) a = 2 and b = 1
In main (), a = 1 and b = 2
In main (), c = 3 and d = 4
In function (Call By Reference Method) c = 4 and d = 3
In main (), c = 4 and d = 3

RESULT:
Thus, the implementation of swap two integers using call by value and call
by reference methods was executed successfully.

2
EX. NO : 3B PAYROLL APPLICATION USING STRUCTURE
DATE :

AIM:
To write a C program to calculate payroll of an employee’s using structure.

ALGORITHM:
1. Start the program.
2. Declare structure with the name emp.
3. Get the employee details like number, name, basic pay, allowance and
deductions.
4. Calculate the net salary using basic pay + allowance - deduction.
5. Print the result.
6. Stop the program.

PROGRAM:
/* Calculate payroll of an employee’s using structure */
#include <stdio.h>
struct emp
{
int empno;
char name [10];
int bpay, allow, ded, npay;
} e [10];

void main ()
{
int i, n;
printf (“Enter the number of employees: ”);
scanf (“%d”, &n);
for (i = 0; i < n; i++)
{
printf (“\nEnter the employee number: ”);
scanf (“%d”, &e [i].empno);
printf (“\nEnter the name: ”);
scanf (“%s”, e [i].name);
printf (“\nEnter the basic pay, allowances & deductions: ”);
scanf (“%d %d %d”, &e [i].bpay, &e [i].allow, &e [i].ded);
e [i].npay = e [i].bpay + e [i].allow – e [i].ded;
}
printf (“\nEmp. No. Name \t Bpay \t Allow \t Ded \t Npay \n\n”;
for (i = 0 ; i < n ; i++)
{
printf (“%d \t %s \t %d \t %d \t %d \t %d \n”, e [i].empno, e [i].name,
e [i].bpay, e [i].allow, e [i].ded, e [i].npay);
}
getch ();

3
}
OUTPUT:
Enter the number of employees: 1
Enter the employee number: 100
Enter the name: Shiva
Enter the basic pay, allowances & deductions:
1000
100
0

Emp.No. Name Bpay Allow Ded Npay

100 Shiva 1000 100 0 1100

RESULT:
Thus, the implementation to calculate payroll of an employee’s using
structure was implemented successfully.

You might also like