This blog is under construction

Sunday, 7 July 2013

C program to add two numbers without third variable

Write a C program to add two numbers without third variable.


  #include <stdio.h>
  int main() {
        int n1, n2;

        /* get the input from the user */
        printf("Enter your first number:");
        scanf("%d", &n1);
        printf("Enter your second number:");
        scanf("%d", &n2);

        /* add the given numbers */
        n1 = n1 + n2;
        printf("Sum of %d and %d is %d\n", n1-n2, n2, n1);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter your first number:100
  Enter your second number:200
  Sum of 100 and 200 is 300





See Also:

No comments:

Post a Comment