Arduino Projects    |   Raspberry Pi  |     Electronic Circuits   |   Electronics Reference Design Library  |   AVR    |    PIC    |    8051    |    Electronic Projects

Count the total negative, positive and zero from a set of Integers

Code: 
/* C Program: Read set of integer numbers and count
   the total negative, Positive and zero  */
#include<stdio.h>
#include<conio.h>
void main()
{
   int x, n_count=0, p_count=0,z_count=0,i=0;
   char ch;
   clrscr();
   do
   {
      printf("\nEnter an integer number -> ",++i);
      scanf("%d",&x);
      
      if(x<0) n_count++;
      else if(x>0) p_count++;
  else z_count++;
      printf("\n\n\nAny more number <<y/>> ? ");
      ch=getche();
   }
   while(ch=='y'||ch=='Y');
   printf("\n\n");
   printf("Total Negative Number : %d\n",n_count);
   printf("Total Positive number : %d\n",p_count);
   printf("Total Zero            : %d\n",z_count);
   getch();
}
Inexpensive, Simple, Easy-to-Use Microcontroller Boards By Texas Instruments

Starting at $9.99 Buy Now

Starting at $17.00 Buy Now

Starting at $12.99 Buy Now

Starting at $12.99 Buy Now

 

You are here