Computer Science, asked by aditya0097, 2 months ago

Take 20 integer inputs from user and print the following:

a) number of positive numbers

b) number of negative numbers

c) number of odd numbers

d) number of even numbers

e) number of 0s.​


BrainlyProgrammer: in which programming language do you want the answer to this question?
aditya0097: python
BrainlyProgrammer: okay..

Answers

Answered by BrainlyProgrammer
5

The programming language used is Python

Here is your answer!!

Answer:-

p,n,o,e,z=0,0,0,0,0

#Here i declared all the variable together, you can also write them seperately

print("Enter 20 integers\n")

for i in range(1,20+1):

n=(int)(input())

if(n>0):

p+=1

if(n<0):

n+=1

if(n%2!=0):

o+=1

if(n%2==0):

e+=1

if(n==0):

z+=1

print("no. of Positive numbers:",p)

print("no. of Negative numbers:",n)

print("no. of odd numbers:",o)

print("no. of even numbers:",e)

print("no. of zeroes",z)

_________________

Variable Description:-

  1. p:- to calculate no. of positive numbers
  2. n:- to calculate no. of negative numbers
  3. o:- to calculate no. of odd numbers
  4. e:- to calculate no. of even numbers
  5. z:- to calculate no. of zeroes

_____

Program Explaination:-

  • The program runs a loop from 1 to 20.
  • Then it accepts the numbers as input from the user
  • Then it checks if number is even or odd or positive or negative or 0 ..if any of them is true, then it executes that statement
  • once Loop value is >20, loop terminates

Output Attached.

Attachments:
Similar questions