This is just the simple program in c program to perform create and display operation on array by using function. Here in this program, the maximal size for the array is 100.
C Program to perform create and display operation on array
Source Code:
// c program to perform create and display operation on array
#include <stdio.h>
// function to create array
void createArr(int arr[100], int n){
// delaration of variable
int i;
//for loop for creation of array
for(i=0; i<n; i++){
if(i == 0){
printf(" \nEnter value:");
scanf("%d",&arr[i]);
}
else{
printf("Enter next value:");
scanf("%d",&arr[i]);
}
}
}
//funtion to display array
void displayArr(int arr[100], int n){
// delaration of variable
int i;
printf("\n\nThis is your created array:");
//for loop for display array
for(i=0; i<n; i++){
printf("%d \t",arr[i]);
}
}
// main program to initailize program
int main() {
// delaration of variable
int arr[100],n;
// statemets for array size
printf("Please enter the size of array:");
scanf("%d",&n);
// call funtion to create array
createArr(arr,n);
// call function to display array
displayArr(arr,n);
return 0;
}
Input:
Please enter the size of array:5
Enter value:12
Enter next value:14
Enter next value:15
Enter next value:16
Enter next value:14
Output:
This is your created array:12 14 15 16 14