Saturday 8 September 2012

Array031

Input some elements in an array and write a program to count the positive and negative elements in that array. 

#include <stdio.h>
#include <conio.h>

void main ( )
{
            int        no[5], i, s = 0, n = 0;
            clrscr ( );
                     
            for ( i = 0; i < 5; i++ )
            {                                             
                            printf ("\n\t\t\t Enter a number...........:"); scanf ("%d", &no[i]);
            }                                                       
                                                            
            for ( i = 0; i < 5; i++ )
            {                                    
                            if ( no[i] >= 0 )
                            {                                 
                                         s++;
                            }                         
                            else           
                            {                                  
                                         n++;
                            }
            }
            printf("\n\n\n\t\t\t Number of positive elements = %d", s);
            printf("\n\n\n\t\t\t Number of negative elements = %d", n);
            getch ( );
}
Click here to contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...