Monday, May 5, 2008

program to find positive, negative and zero integers

Write a program that will ask the user to enter N integers. Find out the following:

(i) Total number of positive integers

(ii) Total number of negative integers

(iii) Total number of integers equal zero

PROGRAM:

#include <iostream.h>

#include <conio.h>

void main() {

clrscr();

int terms,num,pi=0,ni=0,z=0;

cout<<"how many integers do you want to enter: ";

cin>>terms;

for(int i=1;i<=terms;i++) {

cout<<"enter num "<<i<<" : ";

cin>>num;

if(num==0)

z++;

else if(num>0)

pi++;

else

ni++;

}

cout<<"\nTotal Positive Integers: "<<pi;

cout<<"\nTotal Negative Integers: "<<ni;

cout<<"\nTotal Integers which are zero: "<<z;

getch();

}//end of the program

No comments: