Monday, May 5, 2008

program to find numbers greater, less or equal to zero using an array in C++

Write a program that will read 20 float values in a one dimensional array and find out the following:

a. Number of values greater than zero. 

b.Number of values equal to zero.


c. Number of values less than zero.

PROGRAM:

#include <iostream.h>

#include <conio.h>

void main() {

clrscr();

float a[20];

int gz=0,lz=0,z=0;

for(int i=0;i<20;i++) {

cout<<"\nenter value "<<i<<" : ";

cin>>a[i];

if(a[i]>0)

gz++;

else if(a[i]<0)

lz++;

else

z++;

}

cout<<"\nTotal numbers greater than zero: "<<gz;

cout<<"\nTotal numbers less than zero: "<<lz;

cout<<"\nTotal numbers that are zero: "<<z;

getch();

}

No comments: