In this program user ask to check that how to pass one dimensional Array to function. For this user declares the variable regarding to function. Like fstore, fretrieve, fedit these variables will be handy in criteria of function. User also define N value=5.User asks to enter data for matrix and return that all data. Here user make function for the every step like fstore, fretrieve, fedit that is been used along with loop statement that will vary the condition according to filled data. The all three functions are used for data passing next move the user prints the message for previous data and the symbol for skip or edit the data. Display result in the end for this one.
Problem statement:
This is C program that asks user to convey that how to pass data in one dimensional array.
- Declare array type variable.
- Using loop statements.
- Display result on the screen.
Here is C source code for passing value in one dimensional array. The output of this program shown below.
#include <stdio.h>
#define N 5
void fstore1D(int a[], int a_size);
void fretrieve1D(int a[], int a_size);
void fedit1D(int a[], int a_size);
int main()
{
int a[N];
clrscr();
printf("Input Data into the Matrix:\n");
fstore1D(a, N);
fretrieve1D(a, N);
fedit1D(a, N);
fretrieve1D(a, N);
return 0;
}
void fstore1D(int a[], int n)
{
int i;
for ( i = 0; i < n; ++i )
scanf("%d", &a[i]);
}
void fretrieve1D(int a[], int n)
{
int i;
for ( i = 0; i < n; ++i )
printf("%6d ", a[i]);
printf("\n");
}
void fedit1D(int a[], int n)
{
int i, q;
for ( i = 0; i < n; ++i )
{
printf("Prev. data: %d\nEnter 1 to edit 0 to skip.", a[i]);
scanf("%d", &q);
if ( q == 1 )
{
printf("Enter new value: ");
scanf("%d", &a[i]);
}
}
}