Here, we have a basic program example to return the triple of the sum of two numbers if they are equal using different languages. This program is created in c language, c++, Java, and Python.
Program to print the triple of the sum if the given values are equal in C language
01 02 03 04 05 06 07 08 09 10 | #include <stdio.h> int main( void ) { int num1, num2; printf ( "Enter first number: " ); scanf ( "%d" ,&num1); printf ( "Enter second number: " ); scanf ( "%d" ,&num2); return num1 == num2 ? (num1 + num2)*3 : num1 + num2; } |
Program to print the triple of the sum if the given values are equal in C++ language
01 02 03 04 05 06 07 08 09 10 11 12 13 14 | #include<iostream> #include<stdlib.h> #include<cmath> using namespace std; int main() { int num1, num2; cout<< "Enter first number: " ; cin>>num1; cout<< "Enter second number: " ; cin>>num2; return num1 == num2 ? (num1 + num2)*3 : num1 + num2; return 0; } |
Program to print the triple of the sum if the given values are equal in Python language
1 2 3 4 5 6 7 8 9 | num1 = int ( input ( "enter first number: " )) num2 = int ( input ( "enter second number: " )) if num1 = = num2: result = (num1 + num2) * 3 print (result) else : result = num1 + num2 print (result) |
Program to print the triple of the sum if the given values are equal in Java language
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 | import java.io.*; import java.util.Scanner; class sum{ public static void main(String[] args) { int num1,num2,result; Scanner sc = new Scanner(System.in); System.out.print( "Enter the first number: " ); num1=sc.nextInt(); System.out.print( "Enter the second number: " ); num2=sc.nextInt(); result= (num1==num2) ? (num1+num2)* 3 : num1 +num2; System.out.println(result); } } |