IHYPRESS.NET > C PROGRAMMING
HOME | ASP | C | HTML/CSS | JAVASCRIPT | MATLAB | PERL | PHP | PYTHON | RUBY
C > 07. Arrays I (1D) [PROGRAM #02]
CODERESULT
<
/* Problem: This program asks the user for a value and fills all 
100 cells of an array with that value */

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

/* no size in array parameter */
/* just a pointer to array in main */
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], i, value;

	/* initializing the array with a user value */
	/* the 2nd argument must be the size of the array */
	printf ("Enter a value: ");
	scanf ("%d", &value);
        fill_array (x, SIZE, value); 


	/* 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
5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5
>
COPYRIGHT © 2019 IHYPRESS.NET. A DIVISION OF IHY PRESS, KIRKLAND, WA 98083 USA. ALL RIGHTS RESERVED.
SHARE