You are on page 1of 2

Lecture-2

Date: 11.08.2021

What is a function?

A function is a subprogram. It is defined as a set of instructions which performs a specified task. It


returns one and only one value at a time. A function may receive data/value with the help of formal
and/or global parameters. For example consider the following code segment which is a function.

int factorial (int n)


{
if (n==1 || n==0)
return (1);
else return n*factorial(n-1);
}

In this function n is formal parameter.

What is subroutine/procedure?

procedure and function these two terms were used in Pascal language.
subroutine and function these two terms were used in FORTRAN language.

Procedure and subroutine are interchangeably used term. A Procedure/subroutine is a subprogram.


It is defined as a set of instructions which performs a specified task. It may return zero, one, or more
than value at a time. Procedure/subroutine may receive data/value(s) with the help of formal and/or
global parameter(s). For example consider the following code segment which is a
Procedure/subroutine.

void factorial (int n)


{
Int res
if (n==1 || n==0)
{
res=1;
printf(“%d”, res );
else
res = res*factorial(n-1);

printf(“%d”, res );
}

What is an instruction?

An instruction is a lowest level which is recognised by a computer in a program.

What is program?
A program is comprised of set of instruction(s) and/or subprogram(s) which performs a given task.
For example consider the following code segment.
#include<stdio.h>
void main()
{
int number, result;
printf(“Input the number for which factorial will be computed”);
scanf(“%d”, &number);
result=factorial(number);
printf(“Factorial =%d”, result);
}

What is software?
Software is comprised of set of instruction(s) and/or subprogram(s) and /or program(s) which meets
requirement of any given application.

Assignment: Write a program which performs any operation on given data. It should perform the
following operation

(a) Add two numbers


(b) Subtract two numbers
(c) Multiply two numbers
(d) Divide two numbers
(e) Add two string
(f) Subtract two strings
(g) Find length of a string
(h) Computes an expression.

You might also like