You are on page 1of 3

KYAMBOGO UNIVERSITY

FACULTY OF SCIENCE

DEPARTMENT OF COMPUTER SCIENCE


COURSE: BITC YEAR ONE

COURSE UNIT: SCS 1202 (Programming Language Fundamentals)

GROUP 8

IRIMA MADINA 20/U/ITE/ /PE

EKODE JOSHUA 20/U/ITE/9812/PE

BONGOMIN MORRIS 20/U/ITE/ /PE

MUBIRU BENJAMIN 20/U/ITE/ /PE


Questions
15. Write a program to print the array elements in reverse order.
16. What is a function? Write the types of functions.

15. A program to print the array elements in reverse order.


#include<stdio.h>
Int main(){
Int a[5], I;
Printf(“Enter 5 integer numbers\n”);
For(I = 0; I < 5; i++)
Scanf(“%d”, &a[i]);
Printf(“Array elements are:\n”);
For(I = 4; I >= 0; i--)
Printf(“%d\n”, a[i]);
Return 0;}

Output:
Enter 5 integer
numbers1
2
3
4
5
Array elements are:
5
4
3
2
1
16. What is a function?
A function is a block of code that performs a specific task.
A function is also a group of statements that together perform a task. Every c program has at
least one function, which is main(), and all the most trivial programs can define additional
functions.

Types of functions
There are two types of functions in C programming:
Standard library functions
User-defined functions

Standard library functions


The standard library functions are built-in functions in C programming.
These functions are defined in header files. For example,
The printf() is a standard library function to send formatted output to the screen (display output
on the screen). This function is defined in the stdio.h header file.
Hence, to use the printf()function, we need to include the stdio.h header file using #include
<stdio.h>.
The sqrt() function calculates the square root of a number. The function is defined in the math.h
header file.
User-defined function
These are functions created by the user for a specific need or task. Such functions are known as
user-defined functions.
User defined functions contain blocks of statements which are written by the user for tasks
required, these functions have elements that establish them; function declaration, function call
and function definition.
Advantages of user-defined function
The program will be easier to understand, maintain and debug.
Reusable codes that can be used in other programs
A large program can be divided into smaller modules. Hence, a large project can be divided
among many programmers.

You might also like