sum of two variables in C, C++, Java, and Python


 

sum of two variables in C : 


#include <stdio.h>


int main() {

   int a = 5;

   int b = 10;

   int sum = a + b;

   

   printf("The sum of %d and %d is %d", a, b, sum);

   return 0;

}


 sum of two variables in  C++: 


#include <iostream>

int main() {
   int a = 5;
   int b = 10;
   int sum = a + b;
   
   std::cout << "The sum of " << a << " and " << b << " is " << sum;
   return 0;
}


 sum of two variables in java: 

public class Main {
   public static void main(String[] args) {
      int a = 5;
      int b = 10;
      int sum = a + b;
      
      System.out.println("The sum of " + a + " and " + b + " is " + sum);
   }
}


 sum of two variables in python: 

a = 5
b = 10
sum = a + b

print(f"The sum of {a} and {b} is {sum}")


thanks 

Asgartech

No comments: