This blog is under construction

Saturday 6 July 2013

C program to add two numbers

Write a C program to add two numbers.


  #include <stdio.h>
  int main () {
        int a, b, c;

        /* get first number from user */
        printf("Enter your first number:");
        scanf("%d", &a);

        /* get second number from user */
        printf("Enter your second number:");
        scanf("%d", &b);

        /* add two numbers and store the result in c */
        c = a + b;

        /* print the output */
        printf("Sum of %d and %d is %d\n", a, b, c);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter your first number:10  
  Enter your second number:20
  Sum of 10 and 20 is 30





See Also:

No comments:

Post a Comment