How to pass one dimensional array to function in c









#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];
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]);
}
}
}









10. Write a c program to add two numbers without using addition operator.
11. Write a c program to subtract two numbers without using subtraction operator.
15. Write a c program to solve quadratic equation.
18. Write a c program which passes structure to function.
28. Write a c program which takes password from user.
29. Write a scanf function in c which accept sentence from user.
30. Write a scanf function in c which accept paragraph from user.

1 comment:

Anonymous said...

#include
#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]={1,2,3,4,5};
/*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[3]);

}

void fretrieve1D(int a[], int n)
{
int i;
for ( i = 0; i < n; i++ )

printf("%6d ", a[i]);
printf("\n");

}
can some one tell me why the output of this program is 1 2 3 5 5???