Monday, January 21, 2013

write a program to find the sum of the array elements

#include<stdio.h>
  #include<conio.h>
  
  void main()
  {
     int a[5];
     int i,sum=0;
 
     clrscr();
      printf("Enter the array elements\n");
      for (i=0; i<5; i++)
      scanf("%d",&a[i]);
      
      // sum of array elements
      for (i=0; i<5; i++)
      {
        sum=sum+a[i];
      }
      printf("Sum of array elements===%d",sum);
    } // end of main()
 

write a program to find the number of even integers and odd integers in a given array

#include<studio.h>
#include<conio.h>
main()
{
  int a[5],count_even=0,count_odd=0,i;

   for(i=0;i<5;i++)

       scanf("%d",&a[i]);
/* display the number of odd and even intergers */
for(i=0;i<5;i++)
{
   if((a[i]%2 ==0))
          count_even++;
    if((a[i]%2==1))
          count_odd++;
}
printf("%d %d",count_even,count_odd);
getch();
}