Write a C Program to pass array elements to a function

By | 18.03.2017

C Program to pass array elements to a function


Write a C Program to pass array elements to a function. Here’s a Simple Program which take input values into an array and check each value whether it is even or odd using check ( ) function in C Programming Language.

Following C Program ask to the user to enter values that are going to be stored in array. Here we make an intialize an array of 10 elements to be stored in it i.e arr[10].

In this program , we use for loop to input values in the program to store to an array and a check( ) function for checking whether input value is even or odd.


Below is the source code for C Program to pass array elements to a function which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


/* Program to pass array elements to a function */
#include<stdio.h>
void check(int num);
main( )
{
        int arr[10], i;
        printf("Enter the array 10 elements : ");
        for(i=0; i<10; i++)
        {
                scanf("%d", &arr[i]);
                check(arr[i]);
        }
}
void check(int num)
{
        if(num%2==0)
                printf("%d is even\n\n", num);
        else
        printf("%d is odd\n\n", num);
}

OUTPUT : :


Enter the 10 array elements : 
4
4 is even

7
7 is odd

31
31 is odd

67
67 is odd

90
90 is even

6
6 is even

1
1 is odd

87
87 is odd

123
123 is odd

432
432 is even

Above is the source code for C Program to pass array elements to a function which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval. Thanks for reading the post.


Feel Free to ASK !

3 1 vote
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments