URI - BEECROWD - BEE 1064 - Positives and Average Solution in C,C++,Python | URI - BEECROWD - BEE Online Judge Solution 1064 - Positives and Average
Read 6 values that can be floating point numbers. After, print how many of them were positive. In the next line, print the average of all positive values typed, with one digit after the decimal point.
Input
Output
The first output value is the amount of positive numbers. The next line should show the average of the positive values typed.
Input Sample | Output Sample |
7 -5 6 -3.4 4.6 12 | 4 valores positivos 7.4 |
URI - BEECROWD - BEE 1064 - Positives and Average Solution in C,C++,Python | URI Online Judge Solution 1064 - Positives and Average:
Demonstration:
If any number that represents more than zero of anything then it is called as positive number. For example,15 is a positive number because it's greater than zero. Zero is called the origin, and it's neither negative nor positive.
First we need to taking all of the inputs by using for loop. We will run for loop until 6 and increment the count and adding the number with sum variable if the given numbers are greater than zero. Then we need to calculate the average by using this formula:
Average = Sum/Count
Finally, print the result.
N.B: Don't copy paste the code as same. Just try to understand it and try yourself. It would be better for you.
URI Problem 1064 Solution in C :
URI Online Judge 1064 Solve in C : |
#include <stdio.h>
int main()
{
float num,sum=0;
int i,count=0;
for(i=1;i<=6;i++){
scanf("%f",&num);
if(num>0){
sum = sum + num;
count++;
}
}
float average = sum/count;
printf("%d valores positivos\n",count);
printf("%.1f\n",average);
return 0;
}
URI Problem 1064 Solution in C ++:
URI Online Judge 1064 Solve in C++ : |
#include <bits/stdc++.h>
using namespace std;
int main()
{
float num,sum=0;
int i,count=0;
for(i=1;i<=6;i++){
cin >> num;
if(num>0){
sum = sum + num;
count++;
}
}
float average = sum/count;
cout<<count<<" valores positivos"<<endl;
cout<<fixed;
cout<<setprecision(1)<<average<<endl;
return 0;
}
URI Problem 1064 Solution in Python:
URI Online Judge 1064 Solve in Python : |
count=0
sum=0.0
for i in range(1,7):
n = float(input())
if(n>0):
sum = sum + n
count=count+1
average = sum/count
print(f"{count} valores positivos")
print(f"{average:0.1f}")
Previous Post:
0 Response to URI - BEECROWD - BEE 1064 - Positives and Average Solution in C,C++,Python | URI - BEECROWD - BEE Solution 1064
Post a Comment