You are on page 1of 5

Program 5(b)

Aim: write a program for swapping of two number using “Call by


Refrence”
#include<conio.h>

#include<stdio.h>

Void swap(int *a, int *b);

Int main()

Int a=10, b=20;

Printf(“Viraj shoran,A40418013\n”);

Printf(“before swapping the value in main a=%d,b=%d\n”,a,b);

Swap(&a,&b);

Printf(“after swapping the value in main a=%d,b=%d\n”,a,b);

Void swap(int *a, int *b)

Int temp;

temp=*a;

*a=*b;

*b=temp;

Printf(“after swapping the value in function a=%d,b=%d\n\n”,*a,*b);

Viraj Shoran

A40418013
Output:

Viraj Shoran

A40418013
Program 2
Aim: Write a program to search an array using binary search.
#include<stdio.h>

#include<conio.h>

Int main()

Int I,size,num,pos,low,high,mid,arr[20];

Printf(“Viraj Shoran,A40418013\n”);

Printf(“enter number of elements\n”);

Scanf(“%d”,&size);

Printf(“enter the element:\n”);

for(i=0;i<size;i++)

scanf(“%d”,&arr[i]);

printf(“\nenter element to find\n”);

scanf(“%d”,&num);

pos=-1;

low=0;

high=size-1;

while((low<high)&&(pos==-1))

mid=(low+high)/2;

if(arr[mid]==num)

pos=mid+1;

else if(arr[mid]<num)

Viraj Shoran

A40418013
low=mid+1;

else

high=mid-1;

if(pos==-1)

Printf(“\n\n element not found”);

else

Printf(“\n element found at position %d”,pos);

Viraj Shoran

A40418013
Output:

Viraj Shoran

A40418013

You might also like