Académique Documents
Professionnel Documents
Culture Documents
1. Modify the previous program in PART A by adding another function prototype name
loop type void after step 7/
2. Modify the main function as below:
main ( )
{
loop ( ); //a function call
}
int x;
for (x=1; x<=10; x++)
{ printf(“%d”, square (x));
}
Printf(“\n”);
printf(“Array: “);
for (i=0; i<=max; i++)
printf(“%d”, num[i]);
large=num[0];
small=num[0];
7. Using printf statement, print out the large and small values.
8. Execute the program and observe the output.
PART G : PASSING ARRAY TO FUNCTION
return 0;
From this experiment 4, we have learned a lot about the Function in C. A function has three
categories. First, Functions with no arguments (parameter) and no return values. Second,
Functions with arguments (parameters) but no return values and third are Functions with
argument and return values. And has another one that called Recursion Function. Recursion
Function means the function that calls itself either directly or indirectly through another function.
Overall, function means a mini-program where a group of statements are executed. When a user
or the programmer defined function, it will break a large into smaller sets of statements
according to their task. We also had discover that by using function, it have many benefit such as
the program that we make be more manageable. Next, the software is reusability and it will avoid
repeating code so that we don’t need to make the coding more times.
CONCLUSION
From this experiment 5, we had learned a lot about the arrays. An array must have bracket
symbol ‘[ ]‘. An array is a group of memory locations that have the same name and the same
types. It use to allows to store a sequence of values or in the other words, it like a hard disk, the
memory that can save so many values. For instance, if we type int a[5]; it means it store 5
values for example int a[5] = {10,20,30,40,50}; . Array also can store characters too.
Character arrays are capable of storing strings. This is the special ability of an array. To use it we
should type like
But, the function scanf will read characters until computer detect a space, tab, newline or EOF
(end of function)
It means that it has 2 rows and 4 columns. It is similar with matrix equation.
TWO-DIMENSIONAL ARRAY
A two-dimensional array is an array in with both rows and columns. In contrast, gave one
dimensional array is simply a linear sequence of elements.
When we define or use a two-dimensional array, we must supply both the row and column
numbers. Two-dimensional arrays are good for modeling flat surfaces, for example, the screen of
a computer, the layout of a warehouse, or a map. Capital flat surface has two dimensions, and so
a two-dimensional array can easily model it.
This tell the computer that it have 2 row and 6 column. It will be like:
1 2 3 4 5 6
6 5 4 3 2 1
RETURN VALUE DATA TYPE OF FUNCTION
If a function is to use arguments, it must declare variables that accept the values of the
arguments. These variables are called the formal parameters of the function. The formal
parameters behave like other local variables inside the function and are created upon entry into
the function and destroyed upon exit.
While calling a function, there are two ways that arguments can be passed to a function:
Call by value :
This method copies the actual value of an argument into the formal parameter of the function. In
this case, changes made to the parameter inside the function have no effect on the argument
Call by reference :
This method copies the address of an argument into the formal parameter. Inside the function,
the address is used to access the actual argument used in the call. This means that changes made
to the parameter affect the argument.
In general, this means that code within a function cannot alter the arguments used to call the
function and above mentioned example while calling max() function used the same method.
FUNCTION WITH ARGUMENTS AND RETURN VALUES
Function with arguments and return value has same meaning with other function with arguments
that means it will sent arguments from the calling function to the called function but it expects
the result to be returned back from the called function back to the calling function.