Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int data[50];
int i, n, start, stop;
printf("How many integers should I read (1--50)? ");
scanf("%d", &n);
if(n > 50)
{
printf("That value is too large.\n");
exit(1);
}
printf("\nEnter your values, one per line.\n");
for(i = 0; i < n; i++)
scanf("%d", &data[i]);
int j ;
int temp;
int stat,stat1;
for(j=0;j<n;j++)
{
for(i=j;i<n-1;i++)
if(data[j]>data[i+1])
{
temp=data[j];
data[j]=data[i+1];
data[i+1]=temp;
}
}
printf("\nYou entered\n");
for(i = 0; i < n; i++)
printf("%d\n", data[i]);
printf("Enter a Starting Value: ");
scanf("%d", &start);
printf("Enter a Stopping Value: ");
scanf("%d", &stop);
for(i=0;i<n;i++)
{
if(data[i] == start)
{
stat=i;
}
if(data[i] == stop)
{
stat1=i;
}
}
int even=0;
int odd=0;
int count=0;
printf("The elements between %d and %d are\n",start,stop);
for(i=stat;i<=stat1;i++)
{
count++;
printf("%d ", data[i]);
if((data[i]%2)==0)
even++;
else
odd++;
}
printf("\nThe odd is :%d\n",odd);
printf("The even is :%d\n",even);
printf("The count is:%d\n",count);
}
Note: This code will take the start and stop number as a last number only, if you give the duplicate element for an array values.