Yashuop
May 14, 2022

Write a program to swap two inputted integer numbers • using third variable • without using third variable

SOURCE CODE: (using third variable)

#include<stdio.h>

#include<conio.h>

void main ()

{ int a,b;

clrscr();

printf("\n\nEnter two numbers : \n");

scanf("%d%d",&a,&b);

printf("Before swapping......\n");

printf("a= %d\n",a);

printf("b= %d\n",b);

a=a+b;

b=a-b;

a=a-b;

printf("After swapping......\n");

printf("a= %d\n",a);

printf("b= %d\n",b);

getch();

} AGORITHM: (without using third variable)

SOURCE CODE: (without using third variable)

#include<stdio.h> #include<conio.h> void main () { int a,b; clrscr(); printf("\n\nEnter two numbers : \n"); scanf("%d%d",&a,&b); printf("Before swapping......\n"); printf("a= %d\n",a); printf("b= %d\n",b); a=a+b; b=a-b; a=a-b; printf("After swapping......\n"); printf("a= %d\n",a); printf("b= %d\n",b); getch(); }

yashuop

yashuop

explorer

Leave a Reply

Related Posts

Categories