C PROGRAM TO PRINT THE VALUES IN AN ARRAY THAT LIE BETWEEN THE TWO INTEGERS

  Consider the following I/O samples.


SAMPLE INPUT: 5

                            10 3 5 6 8 

                            3 //first number

                            8 // second number

SAMPLE OUTPUT: 5 6     // 5 and 6 lies between 3 and 8


The algorithm used here is :

    1. Input the number of elements.
    2. Input the array elements.
    3. Input the first and second number.
    4. Check for the values using for loop and if condition
    5. Print the output.

C PROGRAM:  

#include<stdio.h>

int main()

{

int n,arr[100],i,first,sec;

printf("Enter the number of elements:");

    scanf("%d",&n);

printf("Enter the array elements:");

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

    scanf("%d",&arr[i]);

printf("Enter the first number");

scanf("%d",&first);

printf("Enter the second number:");

scanf("%d",&sec);

printf("The numbers are:\n");

for(i=0;i<n;i++)  // check for the values

{

    if(arr[i]>first && arr[i]<sec)

        printf("%d\t",arr[i]);

}

return 0;

}


OUTPUT:





The given source code in C program "to find the values that lie between the two integers in an array" is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free. 

If you have any feedback about this article and want to improve this, please comment in the comment section.


Comments

Popular posts from this blog

INVERTED PYRAMID STAR PATTERN

C PROGRAM TO PRINT ALL LEAP YEARS IN A GIVEN RANGE

C PROGRAM TO PRINT THE REMAINING DAYS AND COMPLETED DAYS FROM A GIVEN DATE