sum of two variable in c , c++ , java , python by taking value from user | AsgarTech

 sum of two variables in C, C++, Java, and Python by taking values from the user:



 sum of two variables in C by taking values from the user:


#include <stdio.h>

int main() {
   int a, b, sum;
   
   printf("Enter the first number: ");
   scanf("%d", &a);
   
   printf("Enter the second number: ");
   scanf("%d", &b);
   
   sum = a + b;
   
   printf("The sum of %d and %d is %d", a, b, sum);
   return 0;
}

 sum of two variables in C ++ by taking values from the user:


#include <iostream>

int main() {
   int a, b, sum;
   
   std::cout << "Enter the first number: ";
   std::cin >> a;
   
   std::cout << "Enter the second number: ";
   std::cin >> b;
   
   sum = a + b;
   
   std::cout << "The sum of " << a << " and " << b << " is " << sum;
   return 0;
}

 sum of two variables in java by taking values from the user:


import java.util.Scanner; public class Main { public static void main(String[] args) { int a, b, sum; Scanner input = new Scanner(System.in); System.out.print("Enter the first number: "); a = input.nextInt(); System.out.print("Enter the second number: "); b = input.nextInt(); sum = a + b; System.out.println("The sum of " + a + " and " + b + " is " + sum); } }

sum of two variables in python by taking values from the user:


a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
sum = a + b

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



thanks👍

No comments: