Algorithm
Even Between five Numbers
Adapted by Neilor Tonin, URI Brazil
Make a program that reads five integer values. Count how many of these values are even and print this information like the following example.
Input
The input will be 5 integer values.
Output
Print a message like the following example with all letters in lowercase, indicating how many even numbers were typed.
Input Sample | Output Sample |
7 |
3 valores pares |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h<
int main()
{
int a, i;
int tmp = 0;
for (i = 0; i < 5; ++i)
{
scanf("%d", &a);
if(a < 0) {
a = -a;
}
if(a % 2 == 0) {
tmp++;
}
}
printf("%d valores paresn", tmp>;
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 a;
int tmp = 0;
for (int i = 0; i < 5; ++i)
{
scanf("%i", &a);
if(a < 0) {
a = -a;
}
if(a % 2 == 0) {
tmp++;
}
}
printf("%i valores paresn", 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[]) {
int a, i;
int tmp = 0;
Scanner input = new Scanner(System.in);
for (i = 0; i < 5; ++i)
{
a = input.nextInt();
if(a < 0){
a = -a;
}
if(a % 2 == 0){
tmp++;
}
}
System.out.printf("%d valores paresn", 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(5):
n = float(input())
if(n%2==0):
count=count+1
print(f"{count} valores pares")
Copy The Code &
Try With Live Editor
Input
Output