Tuesday, March 12, 2013

C Language Example # 35 Find positive, negative and zero valued numbers from array

C Language Example # 35 Find positive, negative and zero valued numbers from array.

* Program will find total number of positive numbers from array.
* Program will also find total number of negative and zero numbers from array elements.


//Written by Latest Technology Guide    
//Title : C Language Example # 35 Find positive, negative and zero valued numbers from array.


#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
clrscr();
int a[10]={0},i,positive=0,negative=0,zero=0;

printf("\n Enter Value In Array A [10] : \n");

for(i=0;i<10;i++)
{
printf("A[%d] =",i);
scanf("%d",&a[i]);
}

for(i=0;i<10;i++)
{
if(a[i]==0)
zero=zero+1;
else if (a[i]>0)
positive=positive+1;
else if (a[i]<0)
negative=negative+1;
}

printf("\n********** : Summary of All Number is : **********\n");
printf("\n\t 1: Positive : %d",positive);
printf("\n\t 2: Negative : %d",negative);
printf("\n\t 3: Zero     : %d",zero);

getch();
}



Output:

********* Summary of All Numbers is : *********

1. Positive :
2. Negative :
3. Zero : 

--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 35 Find positive, negative and zero valued numbers from array.

* Program is count total number of positive numbers, zero numbers and negative numbers from the given array elements.
* Program simply checks positive, negative and zero numbers from array using if condition.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

No comments:

Post a Comment

Post a Comment