Program No:-1: Write A Program To Implement Searching of An Element in 2-D Array
Program No:-1: Write A Program To Implement Searching of An Element in 2-D Array
PROGRAM NO:-1
WRITE A PROGRAM TO IMPLEMENT SEARCHING OF AN ELEMENT IN 2-D ARRAY. Algorithm:1. Set k := 1 & loc : = 0 2. Repeat step 3 & 4 while loc : = 0 &k < = n 3. If (item = data[k]) loc : = k Else K=k+1 4. If loc : = 0 ,then Print no. not found Else Print loc is the location of item 5. Exit
PROGRAM NO:-1
WRITE A PROGRAM TO IMPLEMENT SEARCHING OF AN ELEMENT IN 2-D ARRAY
#include<stdio.h> #include<conio.h> void main() { int a[100],n,i,item,loc=-1; clrscr(); printf("\nEnter the number of element:"); scanf("%d",&n); printf("Enter the number:\n"); for(i=0;i<=n-1;i++) { scanf("%d",&a[i]); } printf("Enter the no. to be search\n"); scanf("%d",&item); for(i=0;i<=n-1;i++) { if(item==a[i]) { loc=i; break; } } if(loc>=0) printf("\n%dis found in position%d",item,loc+1); else printf("\nItem does not exits"); getch(); }
OUTPUT:Enter the number of element : 8 Enter the number: 45 78 12 46 58 12 45 Enter the no.to be search 12 12 is found in position 4
PROGRAM NO:-2
WRITE A PROGRAM TO IMPLEMENT ADDITION, SUBTRACTION, MULTIPLICATION AND TRANSPOSE OF MATRIX. Matrix Multiplication Algorithm:Matmul(a,b,m,n,p) 1 for(i=1 to m) 2 for(j = 1 to p) 3 c[i][j] =0; 4 for(k= 1to n) 5 c[i][j] = c[i][j]+a[i][j]*b[i][j] 6 exit
Matrix Transpose Algorithm:Transpose(a,m,n) 1 for(i= 1 to m) for(j= 1 to n) b[i][j]= a[j][i] 2 for (i=1to m) for (j= 1to n) a[i][j]= b[i][j] exit
PROGRAM NO:-2
#include<stdio.h> #include<conio.h> void main( ) { int a[2][2], b[2][2],s[2][2]; int i,j,k; clrscr(); printf("Enter first matrix:\n" ); for( i=1;i<=2;i++) { for( j=1;j<=2;j++) { printf("Enter%d%d\n",i,j); scanf("%d",&a[i][j]); } } printf("Enter second matrix:\n"); for(i=1;i<=2;i++) { for(j=1;j<=2;j++) { printf("Enter %d%d\n",i,j); scanf("%d",&b[i][j]); } } for(i=1;i<=2;i++) { for(j=1;j<=2;j++) { s[i][j]=0; for(k=1;k<=2;k++) { s[i][j] =s[i][j]+a[i][k]*b[k][j]; } } } printf("Matrix Multiplication Is: \n"); for(i=1;i<=2;i++) {
MATRIX ADDITION
#include<stdio.h> #include<conio.h> void main ( ) { int a[2][2],b[2][2],s[2][2],i,j; clrscr (); printf("enter first matrix: \n"); for ( i=1; i<=2; i++) { for ( j=1; j<=2; j++) { printf("Enter %d%d", i,j, "element:"); scanf("%d",&a[i][j]); } } printf("enter second matrix: \n"); for(i=1;i<=2;i++) { for(j=1; j<=2;j++) { printf( "enter %d%d",i + 1 ,j + 1 , "element:"); scanf("%d",&b[i][j]) ; } } for (i=1;i<=2;i++) { for (j=1;j<=2;j++) { s[i][j]= a[i][j]+b[i][j]; } }
ROLL NO:- 13054 printf("The addition matrix is:\n"); for (i=1;i<=2;i++) { for (j=1;j<=2;j++) { printf("%d\n",s[i][j] ); } } getch (); }
TRANSPOSE OF A MATRIX
#include<stdio.h> # include<conio.h> void main() { int a[10][10],b[10][10],i,j,m,n; clrscr(); printf("Enter the order of the matrix\n"); printf("No. of rows : \n"); scanf("%d",&n); printf("No. of columns :\n "); scanf("%d",&m); printf("Enter the matrix elements\n"); for(i=0;i<=n-1;i++) { for(j=0;j<=m-1;j++) { scanf("%d\n",&a[i][j]); b[j][i] = a[i][j]; } } printf("Matrix A was\n "); for(i=0;i<=n-1;i++) { for(j=0;j<=m-1;j++) { printf("%d\n",a[i][j]); } }
ROLL NO:- 13054 printf("Transpose of matrix A is \n"); for(i=0;i<=m-1;i++) { for(j=0;j<=n-1;j++) { printf("%d\n",b[i][j]); } } getch( ); }
OUTPUT:
ENTER FIRST MATRIX: ENTER 11 5 ENTER 12 4 ENTER 21 2 ENTER 22 5 ENTER SECONT MATRIX: ENTER 11 7 ENTER 12 5 ENTER 21 8 ENTER 22 6 THE ADDITION MATRIX
ROLL NO:- 13054 ENTER FIRST MATRIX: ENTER 11 5 ENTER 12 4 ENTER 21 2 ENTER 22 5 ENTER SECONT MATRIX: ENTER 11 7 ENTER 12 5 ENTER 21 8 ENTER 22 6 MATRIX MULTIPLICATION:67 49 54 40
ROLL NO:- 13054 ENTER THE ORDER OF THE MATRIX NO. OF ROWS : 2 NO. OF COLUMNS: ENTER THE MATRIX ELEMENTS 12 11 5 6 MATRIX A WAS 12 11 5 6 TRANSPOSE OF MATRIX A IS 12 5 11 6
PROGRAM NO:-3
WRITE A PROGRAM TO IMPLEMENT STACK USING ARRAY. Algorithm:INSERT PUSH (Item) 1. If (item = max of stack) Print overflow Return 2. Top = top + 1 3. Stack [top] = item 4. Return DELETION POP (Item) 1. If (top = - 1) Print underflow Return 2. Item = stack[top] 3. Top = top 1 4. Return DISPLAY 1. If top = - 1 Print underflow 2. repeat step 3 for i = top to i >= 0 3. Print stack[i] 4. Return
PROGRAM NO:-3
#include<stdio.h> #include<conio.h> #define MAXSIZE 10 void push(); int pop(); void traverse(); int stack[MAXSIZE]; int Top=-1; void main() { int choice; char ch; do { clrscr(); printf("\n1. PUSH "); printf("\n2. POP "); printf("\n3. TRAVERSE "); printf("\nEnter your choice"); scanf("%d",&choice); switch(choice) { case 1: push(); break; case 2: printf("\nThe deleted element is %d",pop()); break; case 3: traverse(); break; default: printf("\nYou Entered Wrong Choice"); } printf("\nDo You Wish To Continue (Y/N)"); fflush(stdin); scanf("%c",&ch); } while(ch=='Y' || ch=='y'); } void push() { int item; if(Top == MAXSIZE - 1) { printf("\nThe Stack Is Full");
ROLL NO:- 13054 getch(); exit(0); } else { printf("Enter the element to be inserted"); scanf("%d",&item); Top= Top+1; stack[Top] = item; }} int pop() { int item; if(Top == -1) { printf("The stack is Empty"); getch(); exit(0); } else { item = stack[Top]; Top = Top-1; } return(item); } void traverse() { int i; if(Top == -1) { printf("The Stack is Empty"); getch(); exit(0); } else { for(i=Top;i>=0;i--) { printf("Traverse the element"); printf("\n%d",stack[i]); }}}
OUTPUT:1: push 2:pop 3: display Enter your choice 1 Enter the number to insert 10 Do you want to continue(y/n) y 1: push 2:pop 3: display Enter your choice 3 No=10 Do you want to continue(y/n) 1: push 2:pop 3: display Enter your choice 2 The delete element in 10 Do you want to continue(y/n)
PROGRAM NO:-4
WRITE A PROGRAM TO IMPLEMENT STACK USING LINKED LIST. Algorithm:PUSH ( ):1. t = newnode( ) 2. Enter info to be inserted 3. Read n 4. t->info = n 5. t->next = top 6. Top = t 7. Return POP ( ):1. If (top = NULL) Print underflow Return 2. x = top 3. Top = top -> next 4. delnode(x) 5. Return DISPLAY ():1. If top = - 1 Print underflow 2. if (temp->next=null) 3. displaynode(x) 4. Return
PROGRAM-4
#include<stdio.h> #include<conio.h> struct stack { int no; struct stack *next; } *start=NULL; typedef struct stack st; void push(); int pop(); void display(); void main() { char ch; int choice,item; do { clrscr(); printf("\n 1: push"); printf("\n 2: pop"); printf("\n 3: display"); printf("\n Enter your choice"); scanf("%d",&choice); switch (choice) { case 1: push(); break; case 2: item=pop(); printf("The delete element in %d",item); break; case 3: display(); break; default : printf("\n Wrong choice"); }; printf("\n do you want to continue(Y/N)"); fflush(stdin); scanf("%c",&ch); } while (ch=='Y'||ch=='y');
ROLL NO:- 13054 } void push() { st *node; node=(st *)malloc(sizeof(st)); printf("\n Enter the number to be insert"); scanf("%d",&node->no); node->next=start; start=node; } int pop() { st *temp; temp=start; if(start==NULL) { printf("stack is already empty"); getch(); exit(); } else { start=start->next; free(temp); } return(temp->no); } void display() { st *temp; temp=start; while(temp->next!=NULL) { printf("\nno=%d",temp->no); temp=temp->next; } printf("\nno=%d",temp->no); }
OUTPUT:1: push 2:pop 3: display Enter your choice 1 Enter the number to insert 10 Do you want to continue(y/n) y 1: push 2:pop 3: display Enter your choice 3 No=10 Do you want to continue(y/n) 1: push 2:pop 3: display Enter your choice 2 The delete element in 10 Do you want to continue(y/n)
PROGRAM NO:-5
WRITE A PROGRAM TO IMPLEMENT QUEUE USING ARRAY. Algorithm:INSERT 1. If (REAR == N) Then [Check for overflow] 2. Print: Overflow 3. Else 4. If (FRONT and REAR == 0) Then [Check if QUEUE is empty] (a) Set FRONT = 1 (b) Set REAR = 1 5. Else 6. Set REAR = REAR + 1 [Increment REAR by 1] [End of Step 4 If] 7. QUEUE[REAR] = ITEM 8. Print: ITEM inserted [End of Step 1 If] 9. Exit DELETE 1. If (FRONT == 0) Then [Check for underflow] 2. Print: Underflow 3. Else 4. ITEM = QUEUE[FRONT] 5. If (FRONT == REAR) Then [Check if only one element is left] (a) Set FRONT = 0 (b) Set REAR = 0 6. Else 7. Set FRONT = FRONT + 1 [Increment FRONT by 1] [End of Step 5 If] 8. Print: ITEM deleted [End of Step 1 If] 9. Exit
PROGRAM-5
#include <stdio.h> #define MAX 50 void insert(); void delet(); void display(); int queue[MAX], rear=-1, front=-1, item; main() { int ch; do { printf("\n\n1. Insert\n2. Delete\n3. Display\n4. Exit\n"); printf("\nEnter your choice: "); scanf("%d", &ch); switch(ch) { case 1: insert(); break; case 2: delet(); break; case 3: display(); break; case 4: exit(0); default: printf("\n\nInvalid entry. Please try again...\n"); } } while(1); getch(); } void insert() { if(rear == MAX-1) printf("\n\nQueue is full."); else { printf("\n\nEnter ITEM: "); scanf("%d", &item);
ROLL NO:- 13054 if (rear == -1 && front == -1) { rear = 0; front = 0; } else rear++; queue[rear] = item; printf("\n\nItem inserted: %d", item); } } void delet() { if(front == -1) printf("\n\nQueue is empty."); else { item = queue[front]; if (front == rear) { front = -1; rear = -1; } else front++; printf("\n\nItem deleted: %d", item); } } void display() { int i; if(front == -1) printf("\n\nQueue is empty."); else { printf("\n\n"); for(i=front; i<=rear; i++) printf(" %d", queue[i]); }
Enter your choise: 1 Enter item: 8 Item inserted: 8 Enter your choice: 3 8 Enter your choice: 2 Item deleted: 2 Enter your choice: 4
PROGRAM NO:-6
WRITE A PROGRAM TO IMPLEMENT QUEUE USING LINKED LIST
#include<stdio.h> struct node { int info; struct node *link; }*front = NULL, *rear = NULL; void insert(); void delet(); void display(); int item; main() { int ch; do { printf("\n\n1.\tInsert\n2.\tDelete\n3.\tDisplay\n4.\tExit\n"); printf("\nEnter your choice: "); scanf("%d", &ch); switch(ch) { case 1: insert(); break; case 2: delet(); break; case 3: display(); break; case 4: exit(0); default: printf("\n\nInvalid choice. Please try again...\n"); }} while(1); getch(); } void insert()
ROLL NO:- 13054 { printf("\n\nEnter ITEM: "); scanf("%d", &item); if(rear == NULL) { rear = (struct node *)malloc(sizeof(struct node)); rear->info = item; rear->link = NULL; front = rear; } else{ rear->link = (struct node *)malloc(sizeof(struct node)); rear = rear->link; rear->info = item; rear->link = NULL; }} void delet() { struct node *ptr; if(front == NULL) printf("\n\nQueue is empty.\n"); else { ptr = front; item = front->info; front = front->link; free(ptr); printf("\nItem deleted: %d\n", item); if(front == NULL) rear = NULL; }} void display() { struct node *ptr = front; if(rear == NULL) printf("\n\nQueue is empty.\n"); else { printf("\n\n"); while(ptr != NULL) { printf("%d\t",ptr->info); ptr = ptr->link; }}}
Enter your choise: 1 Enter item: 8 Item inserted: 8 Enter your choice: 3 8 Enter your choice: 2 Item deleted: 8 Enter your choice: 4
PROGRAM-7
WRITE A PROGRAM TO IMPLEMENT BINARY SEARCH. Algorithm:BINARY SEARCH 1. Low = 1, high = n 2. Repeat step 3 to 5 while low <= high 3. Mid = (low + high) 4. If a[mid] = x Print found at mid Return 5. If (a[mid] < x) Low = mid + 1 Else High = mid 1 6. Print x not found 7. Exit
PROGRAM-7
//binary search #include<stdio.h> #include<conio.h> void main() { int a[100],i,loc,mid,beg,end,n,flag=0,item; clrscr(); printf("How many elements"); scanf("%d",&n); printf("Enter the element of the array\n"); for(i=0;i<=n-1;i++) { scanf("%d",&a[i]); } printf("Enter the element to be searching\n"); scanf("%d",&item); loc=0; beg=0; end=n-1; while((beg<=end)&&(item!=a[mid])) { mid=((beg+end)/2); if(item==a[mid]) { printf("search is successfull\n"); loc=mid; printf("position of the item%d\n",loc+1); flag=flag+1; } if(item<a[mid]) end=mid-1; else beg=mid+1; } if(flag==0) { printf("search is not successfull\n"); } getch(); }
OUTPUT:How many elements8 Enter the element of the array 12 15 19 20 25 28 29 35 Enter the element to be searchng 25 Search is successful Position of the item 5
PROGRAM-8
WRITE A PROGRAM TO IMPLEMENT BUBBLE SORT. Algorithm:BUBBLE SORT 1. Repeat steps 2 & 3 for k = 1 to N-1 2. Set ptr =1 3. Repeat while ptr <= N-k 4. (a) If data[ptr] > data[ptr + 1],then Interchange data[ptr] and data[ptr + 1] (b) ptr = ptr + 1 5. Exit
PROGRAM-8
//bubble sort #include<stdio.h> #include<conio.h> void main() { int a[100],n,i,j,temp; clrscr(); printf("How many elements"); scanf("%d",&n); printf("Enter the element of array"); for(i=0;i<=n-1;i++) { scanf("%d",&a[i]); } for(i=0;i<=n-1;i++) { for(j=0;j<=n-1-i;j++) { if(a[j]>a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } printf("Element of array after the sorting are:\n"); for(i=0;i<=n-1;i++) { printf("%d\n",a[i]); } getch(); }
OUTPUT:How many elements5 Enter the element of the array 12 85 63 36 33 Element of aaay after the sorting are : 12 33 36 63 85
PROGRAM-9
WRITE A PROGRAM TO IMPLEMENT SELECTION SORT. Algorithm:Selection Sort
1. For (i = 0; i <=n-2 ; i++) min = a[i] for (j = i+1 ; j <=n-1 ; j++) If (min >a[j]) Swap (min,a[j]) 2. Exit selection sort #include<stdio.h> #include<conio.h> void main() { int a[100],n,i,j,temp,loc,min; clrscr(); printf("\How many elements:\n"); scanf("%d",&n); printf("Enter the element of array\n"); for(i=0;i<=n-1;i++) { scanf("%d",&a[i]); } min=a[0]; for(i=0;i<=n-1;i++) { min=a[i]; loc=i; for(j=i+1;j<=n-1;j++) { if(a[j]<min) { min=a[j]; loc=j; } }
ROLL NO:- 13054 if(loc!=1) { temp=a[i]; a[i]=a[loc]; a[loc]=temp; } } printf("The number after selection sorting are:\n"); for(i=0;i<=n-1;i++) { printf("%d\n",a[i]); } getch(); }
OUTPUT:-
ROLL NO:- 13054 How many elements 7 Enter the element of the array 22 33 44 56 8 9 11 Element of aaay after the sorting are : 8 9 11 22 33 44 56
PROGRAM-10
PROGRAM-10
#include<stdio.h> void main() { int A[20], N, Temp, i, j; clrscr(); printf("\n ENTER THE NUMBER OF TERMS"); scanf("%d", &N); printf("\n ENTER THE ELEMENTS OF THE ARRAY"); for(i=1; i<=N; i++) { scanf("%d", &A[i]); } for(i=2; i<=N; i++) { Temp = A[i]; j = i-1; while(Temp<A[j] && j>=1) { A[j+1] = A[j]; j = j-1; } A[j+1] = Temp; } printf("\nTHE ASCENDING ORDER LIST IS...:"); for(i=1; i<=N; i++) printf("\n%d", A[i]); getch(); }
OUTPUT:ENTER THE NUMBER OF TERMS6 ENTER THE ELEMENT OF THE ARRAY 4 8 9 10 56 59 THE ASCENDENDING OIRDER IS: 4 8 9 10 56 59
PROGRAM-11
WRITE A PROGRAM TO IMPLEMENT QUICK SORT. Algorithm:QUICK SORT 1. low =l, high = h, key a[(l+h)/2] 2. Repeat through step 7 while (low <= high) 3. Repeat step 4 while (a[low] < key) 4. low = low +1 5. Repeat step 6 while (a[high] > key) 6. high = high 1 7. If (low <= high) a) temp = a[low] b) a[low] = a[high] c) a[high] = temp d) low = low + 1 e) high = high + 1 8. If (l < high) quicksort (a,l,high) 9. If (h>low) quicksort (a,low,h) 10. Exit
PROGRAM-11
//quick sort #include<stdio.h> #include<conio.h> #define max 100 int a[max],n,i,l,h; void main() { void input(void); input(); getch(); } void input(void) { void output(int a[],int n); void quick_sort(int a[],int l,int h); printf("How many elements in the array : "); scanf("%d",&n); printf("\n"); printf("Enter the elemennts : \n"); for(i=0;i<=n-1;i++) { scanf("%d",&a[i]); } l=0; h=n-1; quick_sort(a,l,h); printf("Sorted Array :\n "); output(a,n); } void quick_sort(int a[],int l, int h) { int temp,key,low,high; low=l; high=h; key=a[(low+high)/2]; do { while(key>a[low]) { low++; }
ROLL NO:- 13054 while(key<a[high]) { high--; } if(low<=high) { temp=a[low]; a[low++]=a[high]; a[high--]=temp; } } while(low<=high); if(l<high) quick_sort(a,l,high); if(low<h) quick_sort(a,low,h); } void output(int a[],int n) { for(i=0;i<=n-1;i++) { printf("%d\n",a[i]); } }
OUTPUT:ENTER THE NUMBER OF TERMS6 ENTER THE ELEMENT OF THE ARRAY 45 85 445 25 23 58 THE ASCENDENDING OIRDER IS: 23 25 45 58 85 445
PROGRAM-12
WRITE A PROGRAM TO IMPLEMENT MERGE SORT. Algorithm:Merge Sort ( A, BEG, END ): Description: Here A is an unsorted array. BEG is the lower bound and END is the upper bound. 1. If (BEG < END) Then 2. Set MID = (BEG + END) / 2 3. Call Merge Sort (A, BEG, MID) 4. Call Merge Sort (A, MID + 1, END) 5. Call Merge Array (A, BEG, MID, END) [End of If] 6. Exit
PROGRAM-12
#include<stdio.h> void getdata(int arr[],int n) { int i; printf(" enter the data: "); for(i=0;i<n;i++) { scanf("%d",&arr[i]); } } void display(int arr[],int n) { int i; printf(" "); for(i=0;i<n;i++) { printf("%d ",arr[i]); } getchar(); } void sort(int arr[],int low,int mid,int high) { int i,j,k,l,b[20]; l=low; i=low; j=mid+1; while((l<=mid)&&(j<=high)) { if(arr[l]<=arr[j]) { b[i]=arr[l]; l++; } else
ROLL NO:- 13054 { b[i]=arr[j]; j++; } i++; } if(l>mid) { for(k=j;k<=high;k++) { b[i]=arr[k]; i++; } } else { for(k=l;k<=mid;k++) { b[i]=arr[k]; i++; } } for(k=low;k<=high;k++) { arr[k]=b[k]; } } void partition(int arr[],int low,int high) { int mid; if(low<high) { mid=(low+high)/2; partition(arr,low,mid); partition(arr,mid+1,high); sort(arr,low,mid,high); } }
void main() {
ROLL NO:- 13054 int arr[20]; int n; printf("Enter number of data:"); scanf("%d",&n); getdata(arr,n); partition(arr,0,n-1); display(arr,n); getchar(); }
PROGRAM-13
WRITE A PROGRAM TO IMPLEMENT SWAPPING USING CALL BY VALUE. Algorithm:ENTER (a[10],n) 1. Repeat step 2 for i = 0 to (n-1) 2. Input a[i] 3. Return DISPLAY(c[20],p) 1. Repeat step 2 for k = 0 to p-1 2. Print c[k] 3. Return MAIN( ) 1. Start 2. Input no. of elements in 1st & 2nd array as n & m 3. Enter (a.n) 4. Enter (b,m) 5. i = j = k = 0 6. Repeat step 7 to 12 while ((i < n)&&(j < m)) 7. If (a[i] >= b[j]),goto step 9 8. c[k+1] = a[i+1] 9. If a[i] = b[j] ,goto step 11 10. c[k++] = b[j++] goto step 7 11. c[k++] = a[i++] 12. j++ 13. Repeat step 14 while (i<n) 14. c[k++] = a[i++] 15. Repeat step 16 while m > j 16. c[k++] = b[j++] 17. Display merged arrays as display(c;k) 18. Exit
PROGRAM-13
#include<stdio.h> #include<conio.h> void main( ) { int n,m,i,j,k,c[40],a[20],b[20]; clrscr (); printf("Enter limit for A:"); scanf("%d",&n); printf ("\nEnter limit for B:"); scanf("%d",&m); printf("Enter elements for A:-\n"); for(i=0;i<n;i++) scanf("%d",&a[i]); printf("Enter elements for B:-\n"); for(j=0;j<m;j++) scanf("%d",&b[j]); i=j=k=0; while(i<n&&j<m) { if(a[i]<b[j]) c[k++]=a[i++]; else if(a[i]>b[j]) c[k++]=b[j++]; else { c[k++]=b[j++]; i++; j++; } } if(i<n) { int t; for(t=0;t<n;t++) c[k++]=a[i++]; } if(j<m) { int t;
ROLL NO:- 13054 for(t=0;t<m;t++) { c[k++]=b[j++]; } } printf("\n"); for(k=0;k<(m+n);k++) printf("\t \n %d ",c[k]); getch(); }
OUTPUT:ENTER LIMIT FOR A:3 ENTER LIMIT FOR B :3 ENTER ELEMENT FOR A:1 2 3 ENTER THE ELEMENT FOR B:7 8 9 1 2 3 7 8 9
PROGRAM-14
ROLL NO:- 13054 /*** Program to implement Call By Value ***/ #include <iostream> #include <conio.h> using namespace std; void swap(int, int); main() { int a, b; cout << "Enter two numbers: "; cin >> a >> b; cout << "\nBefore Swapping:\n"; cout << "\na = " << a << " b = " << b; cout << "\n\nAfter Swapping:\n"; swap(a, b); getch() } void swap(int x, int y) { int t; t = x; x = y; y = t; cout << "a = " << x << " b = " << y; }
OUTPUT:
ENTER TWO NUMBER: 2 4 BEFORE SWAPPING: A=2 B=4 AFTER SWWAPPING: A=4 B=2
PROGRAM-15
ROLL NO:- 13054 /*** Program to implement Call By Reference ***/ #include <iostream> #include <conio.h> using namespace std; void swap(int *, int *); main() { int a, b; cout << "Enter Two Numbers: "; cin >> a >> b; cout << "\nBefore Swapping:\n"; cout << "\na = " << a << " b = " << b; cout << "\n\nAfter Swapping:\n"; swap(&a, &b); getch(); } void swap(int *x, int *y) { int t; t = *x; *x = *y; *y = t; cout << "\na = " << *x << " b = " << *
OUTPUT:
ROLL NO:- 13054 ENTER TWO NUMBER: 2 4 BEFORE SWAPPING: A=2 B=4 AFTER SWWAPPING: A=4 B=2