Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to read two positive numbers and interchange it's values using +(add) and -(sub) operators and without using any extra variable

Posted By: Charlie Evans     Category: C Programming     Views: 2894

WRITE A PROGRAM TO READ TWO POSITIVE NUMBERS, SAY N1 AND N2 ARE INTERCHANGE WITHOUT USING ANY EXTRA VARIABLES.
N1=10, N2=20 THEN OUTPUT IS N1=20, N2=10 BY THE MULTIPLICATION (*) AND DIVISION (/).

Code for Program to read two positive numbers and interchange it's values using +(add) and -(sub) operators and without using any extra variable in C Programming

#include<stdio.h>
#include<conio.h>
void main()
{
    int a,b;
    clrscr();
    printf("\n Enter The Value of A: ");
    scanf("%d",&a);
    printf("\n Enter The Value of B: ");
    scanf("%d",&b);

        a = a+b;
        b = a-b;
        a = a-b;
        clrscr();
        printf("\n\t\t According to +,- sign : \n");
        printf("\n\t\t Value of A %d ",a);
        printf("\n\t\t Value of B %d ",b);

    getch();
}




****************************** INPUT *********************************


 Enter The Value of A: 45

 Enter The Value of B: 69




****************************** OUTPUT *********************************


                 According to +,- sign :

                 Value of A 69
                 Value of B 45

  
Share: 



Charlie Evans
Charlie Evans author of Program to read two positive numbers and interchange it's values using +(add) and -(sub) operators and without using any extra variable is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!