Addition of two numbers in C Programming Language

Avatar

 BY TEJAS




C is the Most Popular Programming language in the world. Every developer starts their journy from C programming Language. In IT field there is more demand for C programmers.

For the Addition of Two Numbers in C you have to assign num1, num2, and sum in int but also you can assume it in float. As you wish. Then we print the value using printf(). Then we call scanf() for getting values from keyboard. Then we write a formula
sum = num1 + num2
Then we return call the function printf() to print the answer which is we got.
That's It.



It is a very simple example which is a basic example while learning C language.

Addition of 2 Numbers


In java and Python there is also a same example.


In below video shows program

below here is a C code program and output of c program.

Extension of C Program is .c


main.c :-
    
      #include <stdio.h>
        int main() {
            int number1, number2, sum;

            printf("Enter First Number: ");
            scanf("%d", &number1);

            printf("Enter Second Number: ");
            scanf("%d", &number2);

            // calculating sum
            sum = number1 + number2;

            printf("\nAddition of %d and %d is %d", number1, number2, sum);
            return 0;
        }
    
    
output :-
    
      Enter First Number: 5
      Enter Second Number: 9

      Addition of 5 and 9 is 14 

    
  
    
      #include <stdio.h>
        int main() {
            int number1, number2, sum;

            printf("Enter First Number: ");
            scanf("%d", &number1);

            printf("Enter Second Number: ");
            scanf("%d", &number2);

            // calculating sum
            sum = number1 + number2;

            printf("\nAddition of %d and %d is %d", number1, number2, sum);
            return 0;
        }
    
output :-
    
     
      Enter First Number: 5
      Enter Second Number: 9

      Addition of 5 and 9 is 14

    
  


Search
Advertisement
Share With
Follow us on
Advertisement