0% found this document useful (0 votes)
12 views4 pages

Write Up Part B Journal Program 8,9,10,11

The document provides an overview of arrays and functions in C programming, including definitions and examples of one-dimensional and two-dimensional arrays, as well as user-defined functions. It categorizes user-defined functions based on parameters and return values, detailing their data transfer characteristics. Additionally, it explains the distinction between local and global variables in terms of their scope within a program.

Uploaded by

Vaibhav Kulkarni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Write Up Part B Journal Program 8,9,10,11

The document provides an overview of arrays and functions in C programming, including definitions and examples of one-dimensional and two-dimensional arrays, as well as user-defined functions. It categorizes user-defined functions based on parameters and return values, detailing their data transfer characteristics. Additionally, it explains the distinction between local and global variables in terms of their scope within a program.

Uploaded by

Vaibhav Kulkarni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Write Up –Part B 08

Title: Write a program to read two matrices and perform addition and subtraction on them

Arrays
Definition 1:
An array is a group of related data items that share a common name and a common data type.

Definition 2: An array is a group of homogeneous elements that share a common name.


The array elements are accessed by using a unique number called as index or subscript. The index can
take the values 0, 1, 2, 3, ……. (n-1) where n is total number of elements that array can store.

Two-Dimensional Arrays
Two-dimensional array is defined as group of homogeneous elements that share common name and
are accessed by using two indices or subscripts. We can refer two-dimensional array as “array of
one-dimensional array”.
Pictorially, two-dimensional array can be represented as a table consisting to some rows and columns.

Declaration of two-dimensional array

Syntax:
data_type array_name[row_size][col_size];
where, data_type : specifies the type of elements that will be stored in the array
array_name : specifies the name of the array
row_size : specifies the maximum number of rows that can be stored in the array.
col_size : specifies the maximum number of columns that can be stored in the array.

The total elements that can be stored in a two-dimensional array is equal to (row_size * col_size).

Example: int num[2][3]= {{2, 4, 6}, {1, 3, 5}};

[ 2 4 6
1 3 5 ] 2X3
Write Up –Part B 09
Title: Write a program to read, display and multiply two m x n matrices.
Functions
Definition :
A function is a subprogram or a sub routine that performs a specific task.
There are two categories of functions in C.
1. Library Functions 2. User-Defined Functions

Library Functions : These functions come along with C programming language. Hence, they are
also known as built-in functions. These functions are grouped in various header files.
Example: printf(), scanf(), sqrt(), strcat()
User-Defined Functions: User-defined functions are created and defined by the user or the
programmer that performs a specific task.
Example: addition(),sum(),isprime()

Defining a User-Defined Function


A user-defined function or subroutine can be implemented (defined) as follows:
Write Up –Part B 10
Title: Write a program to check and display if a number is prime by defining isprime( ) function
Categories of User Defined Functions
Depending on whether parameters are passed or not and whether a value is returned or not, a user-
defined function can be categorized as follows:
1. Function with no parameter and with no return value
2. Function with no parameter and with return value
3. Function with parameter and with no return value
4. Function with parameter and with return value

Function with no parameter (argument) and with return value


In this category:
1. The called function does not receive any data from the calling function.
2. The called function returns a value to the calling function.
3. Hence, there is one way data transfer from called function to calling function.
4. The input and processing operations are carried away by the called function (user-defined
function).
5. The output operation is carried away by the calling function.

Example:

Function with parameter (argument) and with return value


In this category:
1. The called function receives data from the calling function.
2. The called function returns a value to the calling function.
3. Hence, there is two-way data transfer between calling function and called function.
4. The input and output operations are carried away by the calling function.
5. The processing operation is carried away by the called function (user-defined function).

Example:
Write Up –Part B 11
Title: Write a program using functions that takes in three arguments - a start temperature (in Celsius), an end
temperature (in Celsius) and a step size. Print out a table that goes from the start temperature to the end
temperature, in steps of the step size; converting each Celsius to Fahrenheit.

Function with no parameter (argument) and with no return value


In this category:
1. The called function does not receive any data from the calling function.
2. The called function does not return any value to the calling function.
3. Hence, there is no data transfer between the calling function and called function.
4. The input, processing and output operations are carried away by the called function (user-defined
function) only.
Example:

Function with parameter (argument) and with no return value


In this category:
1. The called function receives data from the calling function.
2. The called function does not return any value to the calling function.
3. Hence, there is one way data transfer from calling function to called function.
4. The input operation is carried away by the calling function.
5. The processing and output operations are carried away by the called function (user-defined function).
Example:

Local and Global Variables


Local variables declared within a specific block of code, such as inside a function or method are known as
local variables. The scope is limited only to the function.

Global variables are variables that are declared outside of any function or block, usually at the top level of a
program. Their scope is not limited to a specific function, meaning they can be accessed and modified from
any part of the program, including within functions.

You might also like