Tuesday, 27 November 2012

Count the no of Positive Nagative,zero in an Array

using System;
using System.Collections.Generic;
using System.Text;

namespace count_no_of_possi_negat_zero
{
class count
{
static void Main(string[] args)
{
int[] a = new int[20];
int p = 0, ne = 0, z = 0, n,i;
Console.WriteLine("COUNT THE NO OF POSITIVE,NEGATIVE,ZERO IN AN ARRAY");
Console.WriteLine("***************************************************");
Console.WriteLine("\n Enter the no of Elements");
n=int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Elements one by one");
for (i = 1; i <= n; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
for (i = 1; i <= n; i++)
{
if (a[i] > 0)
{
p++;
}
else if (a[i] < 0)
{
ne++;
}
else
{
z++;
}
}
Console.WriteLine("No of Positive={0}", p);
Console.WriteLine("No of Negative={0}", ne);
Console.WriteLine("No of Zeros={0}", z);
}
}
}

No comments:

Post a Comment