C Program–Arrays with Functions (passing Array elements to function)

/*

Program to demonstrate arrays with function in which the array elements are passed as function parameters

*/

#include <stdio.h>
#include <conio.h>
void display(int); //function prototype
int main()
{
    int a[10],i;
    for(i=0;i<10;i++) //getting the array elements
    {
    scanf("%d",&a[i]);
    }
    for(i=0;i<10;i++)
        display(a[i]); //call the function inside the loop, this function called for 10 times
    getch();
    return 0;
}

void display(int a) //function implementation to print the elements, here the parameter is an integer only(means we are passing the array elements)
{
     printf("%d",a);
}

Comments

Popular Posts