0% found this document useful (0 votes)
2 views67 pages

Lesson-4b-Programming With Functions - Copy

The document provides an introduction to functions in C programming, detailing their definitions, types, and importance in structured programming. It covers user-defined and standard library functions, function prototypes, and the advantages of using functions for code reusability and modular design. Additionally, it explains how to declare, define, and call functions, along with their various forms regarding arguments and return values.

Uploaded by

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

Lesson-4b-Programming With Functions - Copy

The document provides an introduction to functions in C programming, detailing their definitions, types, and importance in structured programming. It covers user-defined and standard library functions, function prototypes, and the advantages of using functions for code reusability and modular design. Additionally, it explains how to declare, define, and call functions, along with their various forms regarding arguments and return values.

Uploaded by

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

3 on s

o n- unc ti
L e s s t h F
n w i
e si g ge
n D n g u a
- D ow C - L a
Top I n

08/13/2025 Introduction to Computer Science 1


Objectives

• To learn about functions and how to use them to


write programs with separate modules
• To understand the capabilities of some library
functions in C
• To understand how control flows between function
main and other functions
• To learn how to pass information to functions using
input arguments
• To learn how to return a value from a function

08/13/2025 Introduction to Computer Science 2


Functions-C’s Building Blocks

Road Map!!
Introduction to structured Programming
Functions: Definitions and Creation
Types of Functions
User-Defined Functions
 Standard Library Functions
Function Prototypes
Function Calls
Call by Value
Call by Reference
Variable
08/13/2025
Scope Introduction to Computer Science 3
Introduction to structured
Programming

Structured programming: This is a programming technique of


breaking large complex programs into small manageable
components. This small components are called functions in C
programming language.

Structured programming contains many concepts ranging from


theoretical to application.

The most relevant structured programming concepts include:


 Top-down design
 Code reusability
 Information hidingIntroduction to Computer Science
08/13/2025 4
Structured Programming Concepts

Top-Down Design
Common with procedural languages such as C, top-down design
enables analysts and programmers to define detailed statements
about a system’s specific tasks.
Case Study - 1

Suppose your non-technical boss tells you to program the software for
a new ATM system for the Big Money Bank. You would probably
wonder where to begin as it's a large task filled with complexities and
many details.
08/13/2025 Introduction to Computer Science 5
Case Study -1:ATM System

In C, the top component is the main() function from which other


components are called.

ATM-Major Components Withdraw funds component


 Display balance  Get available balance
 Deposit funds  Compare available balance to amount
 Transfer funds requested
 Withdraw funds  Update customer’s account
 Distribute approved funds
 Reject request
 Print receipt

08/13/2025 Introduction to Computer Science 6


ATM-System

08/13/2025 Introduction to Computer Science 7


Functions: Definitions and
Declaration

What is a Function?
A function is a collection of statements grouped together to do some
specific task. Every C program has at least one function i.e. the main()
Why use functions?
A program is a collection of small tasks that may depend on other
tasks. You can use two approaches to write a program.
a) Write code for all tasks in single place, in the main()
function sequentially
b) Divide code for all tasks into separate functions. Use main()
function to execute all other tasks
08/13/2025 Introduction to Computer Science 8
Functions: Definitions and
Declaration

Advantages of dividing program into functions


•Reusability of code. Functions once defined can be used any several times.

•Abstraction. T o use any function you only need is name and arguments it accepts.
You need not to know how it works internally.

•Modular design of code. Function allows. We can divide program into small
modules. Modular programming leads to better code readability, maintenance and
reusability

•Programs easier to write using functions. You can write code for separate task
individually in separate function.

•Maintenance and debugging of code is easier. In case of errors in a function, you


only08/13/2025
need to debug that particularIntroduction
functionto Computer
insteadScience
of debugging entire program. 9
Functions: Definitions and
Declaration

Function declaration
Like variable declarations functions are also declared. Function declaration
tells the compiler that there exists a function with some name that may be
used later in the program. Function declaration is also known as function
prototype or function signature.
Function declaration
return_type function_name( parameter_list );
A function declaration must be terminated using semicolon; You can declare a
function anywhere in the program. However, it is best practice to declare functions
below pre-processor directives.
Function definition return_type function_name(parameter list)
{
// Function body
}
08/13/2025 Introduction to Computer Science 10
Functions: Definitions and
Declaration

Function declaration and definition syntax must be same. You are free to
put function definition anywhere in your program, below its declaration.
However, it is recommended you to put all declarations below the
main() function.
Run Example Code
Function calling
The most important part of function is its calling. Calling of a function in general is
execution of the function. It transfers program control from driver (current) function to
called function.

Syntax: See Example Code


function_name( parameter_list )
;
08/13/2025 Introduction to Computer Science 11
Functions: Definitions and
Declaration

A function declaration in C programming consists of the following parts:


Return Type − A function may return a value. The return_type is the data
type of the value the function returns.

Function Name −Function name is a valid C identifier that uniquely identifies


the function. You must follow identifier naming rules (similar to variables
rules) while naming a function.

Parameters − A parameter is like a placeholder. When a function is invoked,


you pass a value to the parameter. This value is referred to as actual
parameter or argument.

Function Body − The function body contains a collection of statements that


define what the function does.Introduction to Computer Science
08/13/2025 12
Functions: Definitions and
Declaration

See Code

08/13/2025 Introduction to Computer Science 13


Code Reusability

In the world of application development, code reusability is implemented as


functions in C.

Specifically, programmers create user-defined functions for problems that


generally need frequently used solutions.

The following list is a possible number of transactions a customer


might perform at a single visit to an ATM.
 Deposit monies into a checking account
 Transfer funds from a checking to a savings account
 Withdraw monies from checking
 Print balance
08/13/2025 Introduction to Computer Science 14
Code Reusability

Writing code structures every time you need to access


someone’s balance doesn’t make sense, because you can
write a function that contains the logic and structures to
handle this procedure and then reuse that function when
needed.

Putting all the code into one function that can be called
repeatedly will save you programming time immediately
and in the future if changes to the function need to be
made.
08/13/2025 Introduction to Computer Science 15
Information Hiding

Information hiding is a conceptual process by which programmers conceal


implementation details into functions. Functions can be seen as black boxes. A
black box is simply a component, logical or physical, that performs a task.

08/13/2025 Introduction to Computer Science 16


Types of Functions

Depending on whether a function is defined by the user or already included in


C compilers, there are two types of functions in C programming:

Types of Functions:
 User defined functions
 Standard library functions

User defined functions:


These are self-contained blocks of statements which are written by
the user to compute or perform a task.
08/13/2025 Introduction to Computer Science 17
void functionName()

User-Defined Functions

How user-defined function works?


#include <stdio.h> The execution of a C program begins from the
void functionName() main() function .

{ When the compiler encounters


... .. ... functionName(); inside the main function,
... .. ... control of the program jumps to
}
int main()
void functionName()
{
... .. ... And, the compiler starts executing the codes inside the
... .. ... user-defined function.
functionName();
The control of the program jumps to statement next to
... .. ... ... .. ...
}
functionName();
once all the codes inside the function definition are executed
08/13/2025 Introduction to Computer Science 18
Types of User-Defined Functions

For better understanding of arguments and return value from the function,
user-defined functions can be categorized as:

08/13/2025 Introduction to Computer Science 19


checkPrimeNumber()

Functions with no Argument and no


checkPrimeNumber()
checkPrimeNumber()
checkPrimeNumber()
return Value
checkPrimeNumber()

• Syntax Example: The program checks whether an


functname(); integer entered by the user is a prime number
or not.
• Example:
checkPrimeNumber(); Run Example Code
• Interpretation See Example Code
– the function functname is called
– after functname has finished execution, the program
statement that follows the function call will be
executed
08/13/2025 Introduction to Computer Science 20
return Statement

A function as a collection of statements grouped together to do some


specific task may return a value. However, in no case a function will
return more than one value.

What does it mean by returning a value and where it is returned?

ILLUSTRATION:
Suppose I am the boss of a company. I assigned an audit task to
one of my employee. Consider the audit task as a function.
Employee will complete the task (execute the function) and
return the audit report back to the boss (i.e. me). Similarly,
function returns a value and program control back to the caller
function.
08/13/2025 Introduction to Computer Science 21
return Statement

08/13/2025 Introduction to Computer Science 22


Functions with no arguments and with
return value

For this type of functions we have void in the parameter list but we set the return type
to match the type of value returned by the function.

Function with return but no arguments, returns a value but does not accept any
argument. This type of function communicates with the caller function by returning
value back to the caller.

Syntax: return_type function_name( )


{
Run Example Code // Function body
See Example Code
return some_value;
}
08/13/2025 Introduction to Computer Science 23
Functions with Arguments and no
return value

Function with no return but with arguments, does not return a


value but accepts arguments as input. For this type of function you
must define function return type as void.

Syntax:
void function_name(type arg1, type arg2, ...)
{
// Function body
See Example Code
}
Run Example Code

08/13/2025 Introduction to Computer Science 24


Functions with arguments and with
return value

Function with return value and arguments, returns a value and may accept
arguments. Since the function accepts input and returns a result to the caller,
hence this type of functions are most used and best for modular
programming.

Syntax:
return_type function_name(type arg1, type arg2, ...)
{
// Function body
See Example Code
return some_variable;
} Run Example Code

08/13/2025 Introduction to Computer Science 25


Types of Functions

Which is the best function type for my program?


Choosing a correct function type completely depends on the programming
need.
 Consider function with return and arguments. If your function requires
input from other functions and returns the processed result back to the
caller function. The returned value might be input for other function.

For example - double sqrt(double x), double pow(double x, double y) etc.

 Consider function with return but no argument. If your function does not
require any input from other function. Rather, it just produce some output
that may be input to other functions.

For example - int rand(void),


08/13/2025 int getchar(void)
Introduction to Computer Science etc. 26
Types of Functions

 Consider function with no return but arguments. If your function is


dependent on the input of some other function. But, does not generates
any output that could be consumed by the caller function.

For example - void free(void *ptr), void exit(int status) etc.

 Consider function with no return and no argument. If your function


works as an independent block. It does not communicate with other
functions.

For example - void abort(void)

08/13/2025 Introduction to Computer Science 27


Standard Library Functions

The standard library functions are built-in functions in C


programming to handle tasks such as mathematical computations,
I/O processing, string handling etc. The functions allow reuse tested
code fragments

These functions are defined in the header file. When you include the
header file, these functions are available for use.

You need to prepend library name with #include


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 "stdio.h" header file.
08/13/2025 Introduction to Computer Science 28
Math Library Functions

• Math library functions


– perform common mathematical calculations
– #include <math.h>
• Format for calling functions
– functionName( argument );
• If multiple arguments, use comma-separated list
– printf( "%.2f", sqrt( 900.0 ) );
• Calls function sqrt, which returns the square root of its
argument
• All math functions return data type double
– Arguments may be constants, variables, or expressions
Common Library Functions
Below is the list of common library functions used to implement information
hiding in structured programming.

08/13/2025 Introduction to Computer Science 30


Function sqrt as a “Black Box”

08/13/2025 Introduction to Computer Science 31


Finding the Area and
Circumference of a Circle
Case Study-1

08/13/2025 Introduction to Computer Science 32


Outline of Program for area and
circumference Circle

See Code
08/13/2025 Introduction to Computer Science 33
Calculating the Area and the Circumference of
a Circle

08/13/2025 Introduction to Computer Science 34


Calculating the Area and the Circumference
of a Circle

08/13/2025 Introduction to Computer Science 35


Computing the Weight of a
Batch of Flat Washers
Case Study-2

08/13/2025 Introduction to Computer Science 36


Computing the Rim Area of a Flat Washer

08/13/2025 Introduction to Computer Science 37


Flat Washer Program

08/13/2025 Introduction to Computer Science 38


Flat Washer Program

08/13/2025 Introduction to Computer Science 39


Square Root Program

08/13/2025 Introduction to Computer Science 40


Square Root Program

08/13/2025 Introduction to Computer Science 41


Function Prototypes

A function prototype is simply the declaration of a function that


specifies function's name, parameters and return type. It doesn't
contain function body.
A function prototype gives information to the compiler that the
function may later be used in the program.
Syntax:
returnType functionName(type1 argument1, type2 argument2,...);

Note: It is common programming practice to construct your function prototype


before the actual function is built.
08/13/2025 Introduction to Computer Science 42
Function Prototypes

Example: float addTwoNumbers(int, int);


This function prototype tells C the following things about the function:
• The data type returned by the function—in this case a float data type is
returned
• The number of parameters received—in this case two
• The data types of the parameters—in this case both parameters are integer
data types
• The order of the parameters. Consider the following exaples
void printBalance(int); //function prototype, the function printBalance will not
return a value but takes an integer parameter

int createRandomNumber(void); //function prototype. Function does not


accept any parameters, but it will return an integer value.
08/13/2025 Introduction to Computer Science 43
Function Prototypes

Function prototypes should be placed before the main() function starts:


#include <stdio.h>
int addTwoNumbers(int, int); //function prototype
main()
{ #include <stdio.h>
----- int addTwoNumbers(int, int); //function prototype
f
ro

} int subtractTwoNumbers(int, int); //function prototype


be
um

int divideTwoNumbers(int, int); //function prototype


yn

int multiplyTwoNumbers(int, int); //function prototype


an
yp ave

main()
tot y h
es

{
pro u ma

---
Yo

}
08/13/2025 Introduction to Computer Science 44
Function Prototypes

Functions definition implements the functions prototypes:


#include <stdio.h>
int addTwoNumbers(int, int); //function prototype
main()
{
printf("Nothing happening in here.");
}
//function definition
int addTwoNumbers(int operand1, int operand2)
{
return operand1 + operand2; Note the differences between prototypes
} and definition?

08/13/2025 Introduction to Computer Science 45


An Example

An example to build two functions to perform basic math operations


and return a result-addition and subtraction

See Example Code

Run Example Code

08/13/2025 Introduction to Computer Science 46


Function Prototypes

Purposes of a Function Prototype


 A function prototype ensures that calls to a function are made
with the correct number and types of arguments.
 A function prototype specifies the number of arguments.
 It states the data type of each of the passed arguments.
 It gives the order in which the arguments are passed to the
function.
Benefits of Function Prototypes
 Prototypes save debugging time.
 Prototypes prevent problems that occur when you compile using
functions that were not declared.
 When function overloading occurs, the prototypes distinguish
which function version to call.
08/13/2025 Introduction to Computer Science 47
Function Calls

Function arguments are the inputs passed to a function.


A variable that accepts function argument is known as function parameter.

A function argument is referred to as actual parameter and function


parameter is referred as formal parameter

sed
u
be
ay
s m
erm
se t ably
The ge
te : ha n
No ter-c
in 08/13/2025 Introduction to Computer Science 48
Function Calls

Function argument-
 Call by Value
 Call by reference

Call by Value
Call by value is the default mechanism to pass arguments to a function.
In Call by value, during function call actual parameter value is copied
and passed to formal parameter. Changes made to the formal
parameters does not affect the actual parameter.

See Code Example Run Code Example

08/13/2025 Introduction to Computer Science 49


Function Calls

Call by reference
In call by reference we pass memory location (reference) of actual
parameter to formal parameter. It uses pointers to pass reference of an
actual parameter to formal parameter. Changes made to the formal
parameter immediately reflects to actual parameter.

See Code Example Run Code Example


In the example instead of passing a copy of n1 and n2, we are passing
reference to the swap() function. Operations performed on formal
parameter is reflected to actual parameter (original value). Hence, actual
swapping
08/13/2025
is performed insideIntroduction
swap()toas well as main() function.
Computer Science 50
Variable Scope

Variable scope identifies and determines the life span of any


variable in any programming language. When a variable loses its
scope, it means its data value is lost
Local Variable
Local variables are defined in functions, such as the main()
function, and lose their scope each time the function is executed
#include <stdio.h>
main()
Example
{
int num1;
printf("\nEnter a number: ");
scanf("%d", &num1);
printf("\nYou
08/13/2025 entered %d\n ", num1);
Introduction to Computer Science 51
Variable Scope

Note:
Because local scope variables are tied to their originating functions, you can reuse
variable names in other functions without running the risk of overwriting data.
#include <stdio.h> //function definition
int getSecondNumber(); //function int getSecondNumber ()
prototype {
main() int num1;
{ printf("\nEnter a second number: ");
int num1; scanf("%d", &num1);
printf("\nEnter a number: "); return num1;
}
scanf("%d", &num1);
printf("\nYou entered %d and %d\n ", num1,
getSecondNumber());
}
08/13/2025 Introduction to Computer Science 52
Global Scope

Locally scoped variables can be reused in other functions


without harming one another’s contents. At times, however, you
might want to share data between and across functions. To
support the concept of sharing data, you can create and use
global variables.

Global variables are created and defined outside any function,


including the main() function.

08/13/2025 Introduction to Computer Science 53


Global Scope
#include <stdio.h>
void printLuckyNumber(); //function prototype
int iLuckyNumber; //global variable
main()
{
printf("\nEnter your lucky number: ");
scanf("%d", &iLuckyNumber);
printLuckyNumber();
}
//function definition
void printLuckyNumber()
{
printf("\nYour lucky number is: %d\n", iLuckyNumber);
} 08/13/2025 Introduction to Computer Science 54
Lesson-3: Assignments
and
Group Project

1.Write a function prototype for the following


components:
• A function that divides two numbers and returns the
remainder
• A function that finds the larger of two numbers and
returns the result
• A function that prints an ATM menu—it receives no
parameters and returns no value
2. Build the function definitions for each preceding
function prototype.
08/13/2025 Introduction to Computer Science 55
END OF LESSON3

08/13/2025 Introduction to Computer Science 56


#include <stdio.h> /* Print value of sum */
printf("Sum = %d", sum);
/* Addition function declaration */
int add(int num1, int num2); return 0;
}

/* Main function definition */ /**


int main() * Addition function definition.
{ *
/* Variable declaration */
* Return type of the function is int.
int n1, n2, sum;
* num1 - First parameter of the function of int
type.
/* Input two numbers from user */
printf("Enter two numbers: "); * num2 - Second parameter of the function of
scanf("%d%d", &n1, &n2); int type.
*/
/* int add(int num1, int num2)
* Addition function call. {
* n1 and n2 are parameters passed to int s = num1 + num2;
add function.
* Value returned by add() is stored in /* Return value of sum to the main function */
sum. return s;
*/ }
sum = add(n1, n2);
/*Program is to list square of numbers from 1 to 10*/
/*Function main begins program execution*/
int main(void){
int x; //counter
//loop 10 times and calculate and output square of x each time
for(x=1;x<=10;++x){
printf(“%d”, square(x));//function call

} //end for
puts(“ “);
} //end main

//square function definition return the square of its parameter

int square(int y); //y is a copy of the argument to the function


{
return y*y;
} //end function square
#include <stdio.h> if (flag == 1)
int getInteger(); printf("%d is not a prime number.", n);
else
int main() printf("%d is a prime number.", n);
{ Example-1
int n, i, flag = 0; return 0;
}
// no argument is passed to the
// getInteger() function returns integer
function
entered by the user
// the value returned from the int getInteger()
function is assigned to n {
n = getInteger(); int n;

for(i=2; i<=n/2; ++i) printf("Enter a positive integer: ");


{ scanf("%d",&n);
if(n%i==0){
flag = 1; return n;
break; }
}
}
/** int randPrime()
* C program to print random prime {
numbers int i, n, isPrime;
*/ isPrime = 0;
#include <stdio.h> while(!isPrime)
#include <stdlib.h> // Used for {
rand() function n = rand(); // Generates a random
number
/* Function declaration */ /* Prime checking logic */
int randPrime(); isPrime = 1;
int main() for(i=2; i<=n/2; i++)
{ {
int i; if(n%i==0)
Example: Returns a prime
printf("Random 5 prime numbers { number on each call
are: \n"); isPrime = 0;
for(i=1; i<=5; i++) break;
{ }
printf("%d\n", randPrime()); }
} if(isPrime ==1)
return 0; {
} return n;
/* Function definition */ }
/** int randPrime()
* C program to print random prime {
numbers int i, n, isPrime;
*/ isPrime = 0;
#include <stdio.h> while(!isPrime)
#include <stdlib.h> // Used for rand() {
function n = rand(); // Generates a random number

/* Function declaration */ /* Prime checking logic */


int randPrime(); isPrime = 1;
for(i=2; i<=n/2; i++)
int main() {
{ if(n%i==0)
int i; { Example: Returns a prime
printf("Random 5 prime numbers isPrime = 0; number on each call
are: \n"); break;
for(i=1; i<=5; i++) }
{ }
printf("%d\n", randPrime()); if(isPrime ==1)
} {
return n;
return 0; }
} }
/* Function definition */ }
/**
* C program to print natural numbers using
functions /* Function definition */
*/ void printNaturalNumbers(int start,
int end)
#include <stdio.h> {
printf("Natural numbers from %d
/* Function declaration */ to %d are: \n", start, end);
void printNaturalNumbers(int start, int while(start <= end)
end); {
printf("%d, ", start);
int main()
{ start++;
int s, e; }
printf("Enter lower range to print natural }
numbers: ");
scanf("%d", &s);
printf("Enter upper limit to print natural
numbers: ");
scanf("%d", &e); Example: Program Print all natural numbers between start
to end.
printNaturalNumbers(s, e);
/** /* Function call */
* C check even odd using isEven = evenOdd(num);
function if(isEven == 0)
*/ printf("The given number is
EVEN.");
#include <stdio.h> else
/* Function declaration */ printf("The given number is
int evenOdd(int num); ODD.");
return 0;
}
int main()
{ /* Function definition */
int num, isEven; int evenOdd(int num)
{
printf("Enter a number: "); /* Return 0 if num is even */
scanf("%d", &num); if(num % 2 == 0)
return 0;
else
Example: Program to input a number and return 1;
check if it is even or odd. Define a function
to accepts the number and return a value 0 }
or 1. Return 0 if argument is even, otherwise
return 1.
/*Calculate and display the area and
circumference of a circle*/
/*calculate the
#include<stdio.h> /*prinf scanf *circumference
definitions*/ */
#define PI 3.14159
circumf =2 *PI*radius
int main(void){
/*Display the area and the
double radius, area, circumf; /* input
*circumference
radius, output area and circumf*/
*/
/*Get the circle radius*/
printf(“Enter radius:”); printf(“The area is %.4f\n”,
scanf(“%1f”, &radius); area);
printf(“The circumference is
/*Calculate the area*/ %.4f\n”), cicumf);
area = PI* radius *radius;
return (0);
}
#include <stdio.h>
//Program to add and subtract two numbers
int addTwoNumbers(int, int); //function prototype
int subtractTwoNumbers(int, int); //functionprototype
main()
{
printf("Nothing happening in here.");
}
//function definition
int addTwoNumbers(int num1, int num2)
{
return num1 + num2;
}
//function definition
int subtractTwoNumbers(int num1, int num2)
{
return num1 - num2;
}
/**
* C program to swap two numbers using /* main() function declaration */
call by reference int main()
*/ {
#include <stdio.h> int n1, n2;
/**
printf("Enter two numbers: ");
* *num1 - pointer variable to accept
scanf("%d%d", &n1, &n2);
memory address
* *num2 - pointer variable to accept printf("In Main values before
memory address swapping: %d %d\n\n", n1, n2);
*/
void swap(int * num1, int * num2) /*
{ * &n1 - & evaluate memory
int temp; address of n1
printf("In Function values before * &n2 - & evaluate memory
address of n2
swapping: %d %d\n", *num1, *num2);
*/
swap(&n1, &n2);
temp = *num1;
*num1 = *num2; Call by Reference printf("In Main values after
*num2 = temp; swapping: %d %d", n1, n2);
printf("In Function values after swapping: return 0;
%d %d\n\n", *num1, *num2); }
/** /* main() function definition */
* C program to swap two numbers using int main()
call by value {
*/ int n1, n2;

#include <stdio.h> /* Input two integers from user */


/* Swap function definition */ printf("Enter two numbers: ");
scanf("%d%d", &n1, &n2);
void swap(int num1, int num2)
{ /* Print value of n1 and n2 in before
int temp; swapping */
printf("In Main values before
printf("In Function values before swapping: %d %d\n\n", n1, n2);
swapping: %d %d\n", num1, num2);
/* Function call to swap n1 and n2 */
temp = num1; swap(n1, n2);
num1 = num2; printf("In Main values after swapping:
num2 = temp; %d %d", n1, n2);
printf("In Function values after swapping:
%d %d\n\n", num1, num2); return 0;
} } Example: Function:to swap two numbers.

You might also like