A program to accept an array and diplay it on the console using functions. Program should contain 3 functions including main() function. Next two functions for accepting values to the array, and display array values on the console respectively.
#include <stdio.h>
#include <stdlib.h>
void getarray(int a[],int size);
void displayarray(int a[],int size);
int main(void) {
int a[20],size;
getarray(a,size);
displayarray(a,size);
return EXIT_SUCCESS;
}
void getarray(int a[],int size){
int i;
printf("enter the size of the array");
scanf("%d",&size);
for(i=0;i<size;i++){
scanf("%d",&a[i]);
}
}
void displayarray(int a[],int size){
int i;
for(i=0;i<size;i++){
printf("%d\t",a[i]);
}
}
This is what I tried. I did'nt get proper output.
My output:
Enter the size of the array3
1
2
3
And stopped here.
What are the mistake in it? Or is there another way to get result?