Algorithm
Positive Numbers
Adapted by Neilor Tonin, URI Brazil
Write a program that reads 6 numbers. These numbers will only be positive or negative (disregard null values). Print the total number of positive numbers.
Input
Six numbers, positive and/or negative.
Output
Print a message with the total number of positive numbers.
Input Sample | Output Sample |
7 |
4 valores positivos |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main()
{
double n;
int tmp = 0, i;
for (i = 0; i < 6; ++i)
{
scanf("%lf", &n);
if(n > 0){
tmp++;
}
}
printf("%i valores positivosn", tmp);
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Java Programming
Code -
Java Programming
import java.util.*;
public class Main {
public static void main(String args[]) {
double n;
int tmp = 0, i;
Scanner sc = new Scanner(System.in);
for (i = 0; i < 6; ++i)
{
n = sc.nextDouble();
if(n > 0){
tmp++;
}
}
System.out.printf("%d valores positivosn", tmp);
}
}
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with Python Programming
Code -
Python Programming
count = 0
for i in range(6):
nums = float(input())
if(nums>0):
count+=1
print(f'{count} valores positivos')
Copy The Code &
Try With Live Editor
Input
Output