Computer Science, asked by p1998p, 1 year ago

write a program in c to print one dimensional array.

Answers

Answered by p1998
2
#include <stdio.h>

/** funtion : readArray()
input : arr ( array of integer ), size
to read ONE-D integer array from standard input device (keyboard).
**/
void readArray(int arr[], int size)
{
int i =0;

printf("\nEnter elements : \n");

for(i=0; i<size; i++)
{
printf("Enter arr[%d] : ",i);
scanf("%d",&arr[i]);
}
}

/** funtion : printArray()
input : arr ( array of integer ), size
to display ONE-D integer array on standard output device (moniter).
**/
void printArray(int arr[],int size)
{
int i =0;

printf("\nElements are : ");

for(i=0; i<size; i++)
{
printf("\n\tarr[%d] : %d",i,arr[i]);
}
printf("\n");
}

int main()
{
int arr[10];

readArray(arr,10);
printArray(arr,10);

return 0;
}

Output:-
arr[0] : 1
Enter arr[1] : 2
Enter arr[2] : 3
Enter arr[3] : 4
Enter arr[4] : 5
Enter arr[5] : 6
Enter arr[6] : 7
Enter arr[7] : 8
Enter arr[8] : 9
Enter arr[9] : 10

Elements are :
arr[0] : 1
arr[1] : 2
arr[2] : 3
arr[3] : 4
arr[4] : 5
arr[5] : 6
arr[6] : 7
arr[7] : 8
arr[8] : 9
arr[9] : 10
Similar questions