IHYPRESS.NET > C PROGRAMMING
HOME | ASP | C | HTML/CSS | JAVASCRIPT | MATLAB | PERL | PHP | PYTHON | RUBY
C > 07. Arrays I (1D) [PROGRAM #05]
CODERESULT
<
/* Problem: This programs fills an array with a value 
submitted by the user. */

#include <stdio.h>
#define SIZE 100 /* size of the array */

/* array parameter can be expressed as a pointer */
/* *list is the same thing as list[] */
void
fill_array (int *list, int n, int in_value)
{
	int i;
	for (i=0; i<n; ++i)
		list[i] = in_value;
}

int 
main (void)
{

     	int x[SIZE];
     	int i, n;

	/* user enters a number */
	printf ("Enter an integer number: ");
	scanf ("%d", &n);
	

	/* &x[0] is the address of the x[0] */
	/* which is the same thing as x */
        fill_array (&x[0], SIZE, n); 


	/* printing the array for verification */
	for (i=0; i<SIZE; ++i)
		printf ("%d  ", x[i]);

	return (0);
}
 

Legend: preprocessor directives | variable declarations main function | helper functions | user-defined structures comments
Enter an integer number: -47
-47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47 -47
>
COPYRIGHT © 2019 IHYPRESS.NET. A DIVISION OF IHY PRESS, KIRKLAND, WA 98083 USA. ALL RIGHTS RESERVED.
SHARE