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

Exp10 Writeup-1

10

Uploaded by

chiragmore0077
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Exp10 Writeup-1

10

Uploaded by

chiragmore0077
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

EXPERIMENT NO:- 10

Date of Performance :

Date of Submission :

Aim: Program to demonstrate pointers in C.


10a. Write a program to swap two numbers using call by value.
10b. Write a program to swap two numbers using call by method.

10a. ALGORITHM: (Main Function)


STEP1: Start.
STEP2: Read two numbers.
STEP3: Display the values before calling function.
STEP4: Call function swap by passing inputted numbers values.
STEP5: Display the values after calling function.
STEP6: Stop.

ALGORITHM: (Function void swap (int a, int b))


STEP1: Declare temp variable t.
STEP2: Assign value of a to temp.
STEP3: Assign value of b to a.
STEP4: Assign value of temp to b.
STEP5: Display the result after swapping in function.
STEP6: Return to main program.

10b. ALGORITHM: (Main Function)


STEP1: Start.
STEP2: Read two numbers.
STEP3: Display the values before calling function.
STEP4: Call function swap by passing address of an inputted numbers.
STEP5: Display the values after calling function.
STEP6: Stop.
ALGORITHM: (Function void swap (int *p1, int *p2))
STEP1: Declare temp variable t.
STEP2: Assign value of *p1 to temp.
STEP3: Assign value of *p2 to *p1.
STEP4: Assign value of temp to *p2.
STEP5: Display the result after swapping in function.
STEP6: Return to main program.
10a. Write a program to swap two numbers using call by value.

CODE:

#include<stdio.h>
#include<math.h>
void main()
{
int a,b;
void swap (int a, int b);
printf("Enter two numbers:");
scanf("%d %d",&a,&b);
printf("The values of a and b in the main function before calling the swap function are
%d and %d\n",a,b);
swap(a,b);
printf("The values of a and b in main function after calling the swap function are %d
and %d\n",a,b);

}
void swap (int a, int b)
{
int temp;
temp=a;
a=b;
b=temp;
printf("The values of a and b in the swap function after swapping are %d and %d\
n",a,b);
}
OUTPUT:
10b. Write a program to swap two numbers using call by method.

CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
void swap (int *p1, int *p2);

printf("Enter two numbers:");


scanf("%d %d",&a,&b);
printf("The values of a and b in the main function before calling the swap function are
%d and %d\n",a,b);
swap(&a,&b);
printf("The values of a and b in main function after calling the swap function are %d
and %d\n",a,b);

}
void swap (int *p1, int *p2)
{
int temp;
temp=*p1;
*p1=*p2;
*p2=temp;
printf("The values of a and b in the swap function after swapping are %d and %d\
n",*p1,*p2);
}

OUTPUT:
CONCLUSION:

Sign & Remark

R1 R2 R3 R4 R5 Total Signature
(3 (3 (3 (3 Mark) (3 Mark) (15 Marks)
Marks) Marks) Marks)

You might also like