C program to swap the values using a temporary location.

 

C program

C PROGRAM

C program to swap the values using a temporary location

#include <stdio.h>
#include <conio.h>
void swap(int*,int*); 
void main ()
{
  int a,b;
  clrscr();
  printf ("\nenter the numbers:");
  scanf("%d%d",&a,&b);
  printf ("\nbefore swapping:a=%d,b=%d",a,b);
  swap(&a,&b);
  printf("\nafter swapping :a=%d,b=%d",a,b);
  getch();
  }
  void swap(int *num1,int *num2)
  {
    int temp;
    temp=*num1;
    *num1=*num2;
    *num2=temp;
    return (temp);
    } 

OUTPUT :

enter the numbers:2
6

before swapping:a=2,b=6
after swapping :a=6,b=2
Process finished.



infinitynotes00


No comments:

Post a Comment




Copyright Ⓒ 2022 | Mechpedia | All Right Reserved.