Algorithm
media = (a/10 * 2) + (b/10 * 3) + (c/10 * 5);
Average 2
Adapted by Neilor Tonin, URI Brazil
Read three values (variables A, B and C), which are the three student's grades. Then, calculate the average, considering that grade A has weight 2, grade B has weight 3 and the grade C has weight 5. Consider that each grade can go from 0 to 10.0, always with one decimal place.
Input
The input file contains 3 values of floating points (double) with one digit after the decimal point.
Output
Print the message "MEDIA"(average in Portuguese) and the student's average according to the following example, with a blank space before and after the equal signal.
Input Samples | Output Samples |
5.0 |
MEDIA = 6.3 |
5.0 |
MEDIA = 9.0 |
10.0 |
MEDIA = 7.5 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main()
{
double a, b, c, media;
scanf("%lf%lf%lf", &a, &b, &c);
media = (a/10 * 2) + (b/10 * 3) + (c/10 * 5);
printf("MEDIA = %.1lf\n", media);
return 0;
}
Copy The Code &
Try With Live Editor
Input
6.0
7.0
Output
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double a, b, c, media;
cin >> a >> b >> c;
media = (a/10 * 2) + (b/10 * 3) + (c/10 * 5);
cout << "MEDIA = "<< fixed << setprecision(1) << media << endl;
return 0;
}
Copy The Code &
Try With Live Editor
Input
6.0
7.0
Output
#3 Code Example with Java Programming
Code -
Java Programming
import java.util.Scanner;
public class Main{
public static void main(String[] args){
double a, b, c, med;
Scanner sc =new Scanner(System.in);
a =sc.nextDouble();
b =sc.nextDouble();
c =sc.nextDouble();
med = (a/10 * 2) + (b/10 * 3) + (c/10 * 5);
String media = String.format("MEDIA = %,.1f", med);
System.out.print(media +"\n");
}
}
Copy The Code &
Try With Live Editor
Input
10.0
10.0
Output
#4 Code Example with Python Programming
Code -
Python Programming
a = float(input())
b = float(input())
c = float(input())
media = (a/10 * 2) + (b/10 * 3) + (c/10 * 5);
print("MEDIA = %0.5f" %media)
Copy The Code &
Try With Live Editor
Input
10.0
5.0
Output
#5 Code Example with C++ Programming
Code -
C++ Programming
using System;
class URI {
static void Main(string[] args) {
double a, b, c;
a = Convert.ToDouble(Console.ReadLine());
b = Convert.ToDouble(Console.ReadLine());
c = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("MEDIA = " + ((a/10 * 2) + (b/10 * 3) + (c/10 * 5)).ToString("0.00000"));
Console.ReadKey();
}
}
Copy The Code &
Try With Live Editor
Input
10.0
5.0
Output
Demonstration
Beecrowd Online Judge Solution 1006 Average 2 - Solution in C, C++, Java, Python and C#