Program to compute the sum of the two given integers. Return 18 if one of the integer values given is in the range 10..20 inclusive.

Here, we have a basic program example to calculate the sum of two numbers and return 18 if one of the number is within the range of 10-20 using different languages. This program is created in c language, c++, Java, and Python.

Program to calculate the sum and check if the number is within the range in C language

#include <stdio.h>
#include <stdlib.h>

int main(void){
    int num1, num2;
    printf("Enter first number: ");
    scanf("%d",&num1);
    printf("Enter second number: ");
    scanf("%d",&num2);
    printf("\n%d",test(num1, num2));
    }
    int test(int x, int y)
         {
            return (x >= 10 && x <= 20) || (y >= 10 && y <= 20) ? 18 : x + y;
         }

Program to calculate the sum and check if the number is within the range in C++ language

#include <iostream>
using namespace std;
int test(int x, int y)
        {
            return (x >= 10 && x <= 20) || (y >= 10 && y <= 20) ? 18 : x + y;
        }
int main()
 {
  int num1,num2;
  cout << "enter first number: " ;
  cin>>num1;
  cout << "enter second number: " ;
  cin>>num2;
  cout<<"The result is: ";
  cout << test(num1, num2) << endl;
  return 0;
}

Program to calculate the sum and check if the number is within the range in Python language

num1=int(input("enter first number : "))
num2=int(input("enter second number : "))
if (num1 >= 10 and num1 <= 20) or (num2 >= 10 and num2 <= 20):
    print("18")
else:
    print(num1 + num2)

Program to calculate the sum and check if the number is within the range in Java language

import java.util.Scanner;
class test{
  public static void main(String[] args)
    {
       int num1, num2;
       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();

   if((num1 >= 10 && num1 <= 20) || (num2 >= 10 && num2 <= 20)){
              System.out.println("18");
           }
   else{
             System.out.println(num1 + num2);
            }

}
}