Ex 3 - DSCP Lab
Ex 3 - DSCP Lab
Ex 3 - DSCP Lab
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;
}
1
a = b;
b = temp;
printf (“\n In function (Call By Value Method) a = %d and b = %d”, a,b);
}
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
RESULT:
Thus, the implementation to calculate payroll of an employee’s using
structure was implemented successfully.