Algorithm
Weighted Averages
Adapted by Neilor Tonin, URI Brazil
Read an integer N, which represents the number of following test cases. Each test case consists of three floating-point numbers, each one with one digit after the decimal point. Print the weighted average for each of these sets of three numbers, considering that the first number has weight 2, the second number has weight 3 and the third number has weight 5.
Input
The input file contains an integer number N in the first line. Each N following line is a test case with three float-point numbers, each one with one digit after the decimal point.
Output
For each test case, print the weighted average according with below example.
Input Sample | Output Sample |
3 |
5.7 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main()
{
int n;
double a;
double b;
double c;
scanf("%i", &n);
for (int i = 0; i < n; ++i)
{
scanf("%lf", &a);
scanf("%lf", &b);
scanf("%lf", &c);
double med = ((a/10) * 2) + ((b/10) * 3) + ((c/10) * 5);
printf("%.1fn", med);
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <cstdio>
int main()
{
int n;
double a;
double b;
double c;
scanf("%i", &n);
for (int i = 0; i < n; ++i)
{
scanf("%lf", &a);
scanf("%lf", &b);
scanf("%lf", &c);
double med = ((a/10) * 2) + ((b/10) * 3) + ((c/10) * 5);
printf("%.1fn", med);
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Java Programming
Code -
Java Programming
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int N;
float value1, value2, value3;
float average;
Scanner input =new Scanner(System.in);
N = input.nextInt();
for (int i = 1; i < = N; i++) {
value1 = input.nextFloat();
value2 = input.nextFloat();
value3 = input.nextFloat();
average = ( value1*2 + value2*3 + value3*5 ) / 10;
System.out.printf("%.1fn", average);
}
}
}
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with Python Programming
Code -
Python Programming
n=int(input())
for i in range(n):
a,b,c=list(map(float,input().split()))
total=(a*2+b*3+c*5)/10
print("%0.1f"%total)
Copy The Code &
Try With Live Editor
Input
Output