The program must accept two numbers and print their average (up to two decimal places).
Example Input/Output 1:
Input:
10 4
Output:
7.00
Example Input/Output 2:
Input:
20 3
Output:
11.50
Python
X, Y = map(int, input().split())
print(format((X+Y)/2, '.2f'))
Java
import java.util.*;
public class Hello {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
System.out.printf("%.2f", (num1+num2)/2.0);
}
}
C
#include <stdlib.h>
#include <stdio.h>
int main()
{
int num1, num2;
scanf("%d%d", &num1, &num2);
printf("%.2f", (num1 + num2) / 2.0);
}
C++
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int num1, num2;
cin >> num1 >> num2;
cout << fixed << setprecision(2) << (num1 + num2)/2.0;
return 0;
}
Leave a Reply