SlideShare a Scribd company logo
UNIVERSITI TUN HUSSEIN ONN MALAYSIA
              FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING
              BTI 10202: COMPUTER PROGRAMMING


                                        LAB 10 : Functions (cont)

 NAME : _____________________________________
 MATRICS NO.: _______________ DATE : ____________                        MARK



Exercise 1: Type the coding below and answer the following questions:

   1          #include<stdio.h>
   2          #include<conio.h>
   3          void swapByValue(int a, int b );
   4          void swapByAddress(int *a, int *b );
   5
   6          void swapByValue(int a, int b ){
   7          int temp;
   8          Temp = a;
   9          a = b;
   10         b = temp;
   11
   12         }
   13         void swapByAddress(int *a, int *b ){
   14         int temp;
   15         temp = *a;
   16         *a = *b;
   17         *b = temp;
   18
   19         }
   20         int main(void){
   21         int a, b;
   22         a = 8, b = 5;
   23
   24         printf("nIntially a=%3d and b=%3d ", a, b);
   25         swapByValue(a, b);
   26         printf("nAfter swap by value a=%3d and b=%3d", a, b);
   27         swapByAddress(&a, &b);
   28         printf("nAfter swap by address a=%3d and b=%3d", a, b);
   29         getch();
   30         return 0;
   31}

         i.        What is the output of the coding? Output:
ii.    Explain the difference between passing by value and address
       By value: ________________________________________________________
       ________________________________________________________________
       ________________________________________________________________
       By Address: ______________________________________________________
       ________________________________________________________________
       ________________________________________________________________

iii.   Add    printf("nnIn swap by value function a=%3d and b=%3d", a, b); at line 11
       Add    printf("nnIn swap by address a=%3d and b=%3d", *a, *b); at line 18

       What is the output of the coding? Explain:




       By value: ________________________________________________________
       ________________________________________________________________
       ________________________________________________________________
       By Address: ______________________________________________________
       ________________________________________________________________
       ________________________________________________________________
Exercise 2 : Type the coding below and answer the following questions:

            #include <stdio.h>
            #include <conio.h>

             main ()
            {
              int n;
              long faktorial ( int );
              printf("Enter n (1-15): ");
              scanf ("%d",&n);
              printf ("%d! = %dn",n, faktorial ( n ) );
              getch();
            }

            long faktorial ( int n ) {
              if ( n == 0 )
                return 1;
              else
                return (n * faktorial ( n -1 ));
            }



       i.          What is the output of the coding? Output:




       ii.         Explain how the coding work (input: 3) :
                   ________________________________________________________________
                   ________________________________________________________________
                   ________________________________________________________________
                   ________________________________________________________________
                   ________________________________________________________________
                   ________________________________________________________________
                   ________________________________________________________________
                   ________________________________________________________________
                   ________________________________________________________________
                   ________________________________________________________________

More Related Content

What's hot

C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11
Rumman Ansari
 
C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloading
mohamed sikander
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
SURBHI SAROHA
 
Functions
FunctionsFunctions
Functions
Jesmin Akhter
 
Function overloading(C++)
Function overloading(C++)Function overloading(C++)
Function overloading(C++)
Ritika Sharma
 
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAMSIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
Function recap
Function recapFunction recap
Function recap
alish sha
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
Rumman Ansari
 
Lecture 8- Data Input and Output
Lecture 8- Data Input and OutputLecture 8- Data Input and Output
Lecture 8- Data Input and Output
Md. Imran Hossain Showrov
 
Lecture 12 - Recursion
Lecture 12 - Recursion Lecture 12 - Recursion
Lecture 12 - Recursion
Md. Imran Hossain Showrov
 
Intro to c chapter cover 1 4
Intro to c chapter cover 1 4Intro to c chapter cover 1 4
Intro to c chapter cover 1 4
Hazwan Arif
 
Lecture 18 - Pointers
Lecture 18 - PointersLecture 18 - Pointers
Lecture 18 - Pointers
Md. Imran Hossain Showrov
 
Functions
FunctionsFunctions
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
Saranya saran
 
Labsheet2
Labsheet2Labsheet2
Labsheet2
rohassanie
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
hassaanciit
 
C語言基本資料型別與變數
C語言基本資料型別與變數C語言基本資料型別與變數
C語言基本資料型別與變數
吳錫修 (ShyiShiou Wu)
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
Rumman Ansari
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c language
MomenMostafa
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
Abhishek Sinha
 

What's hot (20)

C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11
 
C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloading
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
 
Functions
FunctionsFunctions
Functions
 
Function overloading(C++)
Function overloading(C++)Function overloading(C++)
Function overloading(C++)
 
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAMSIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
 
Function recap
Function recapFunction recap
Function recap
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
Lecture 8- Data Input and Output
Lecture 8- Data Input and OutputLecture 8- Data Input and Output
Lecture 8- Data Input and Output
 
Lecture 12 - Recursion
Lecture 12 - Recursion Lecture 12 - Recursion
Lecture 12 - Recursion
 
Intro to c chapter cover 1 4
Intro to c chapter cover 1 4Intro to c chapter cover 1 4
Intro to c chapter cover 1 4
 
Lecture 18 - Pointers
Lecture 18 - PointersLecture 18 - Pointers
Lecture 18 - Pointers
 
Functions
FunctionsFunctions
Functions
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
 
Labsheet2
Labsheet2Labsheet2
Labsheet2
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
 
C語言基本資料型別與變數
C語言基本資料型別與變數C語言基本資料型別與變數
C語言基本資料型別與變數
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c language
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 

Viewers also liked

2008 annualreport
2008 annualreport2008 annualreport
2008 annualreport
hiatuan
 
External
ExternalExternal
External
hiatuan
 
Shrinkage Estimation of Linear Panel Data Models Under Nearly Singular Design
Shrinkage Estimation of Linear Panel Data Models Under Nearly Singular DesignShrinkage Estimation of Linear Panel Data Models Under Nearly Singular Design
Shrinkage Estimation of Linear Panel Data Models Under Nearly Singular Design
raffaelesaggio
 
Ventajas y desventajas
Ventajas y desventajasVentajas y desventajas
Ventajas y desventajas
Leonardo Eras
 
How to manage your home improvement projects
How to manage your home improvement projectsHow to manage your home improvement projects
How to manage your home improvement projects
HomeZada
 
Sistem Presensi Siswa Berbasis Barcode Scanner.
Sistem Presensi Siswa Berbasis Barcode Scanner.Sistem Presensi Siswa Berbasis Barcode Scanner.
Sistem Presensi Siswa Berbasis Barcode Scanner.
Increative Technology Indonesia
 
Ud 0 final juani
Ud 0 final juaniUd 0 final juani
Ud 0 final juanijuanapardo
 
A Design Thinking Approach to Online Engagement
A Design Thinking Approach to Online EngagementA Design Thinking Approach to Online Engagement
A Design Thinking Approach to Online Engagement
Cloud View Pte Ltd
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5
alish sha
 
Investment presentation
Investment presentationInvestment presentation
Investment presentation
Charles Beaubien
 
Celula mitose e_moiose new
Celula mitose e_moiose newCelula mitose e_moiose new
Celula mitose e_moiose newjuanapardo
 
The Secret Service Methods for Finding and Fixing Unexplainable Distributed S...
The Secret Service Methods for Finding and Fixing Unexplainable Distributed S...The Secret Service Methods for Finding and Fixing Unexplainable Distributed S...
The Secret Service Methods for Finding and Fixing Unexplainable Distributed S...
Jörg Bächtiger
 
What are the causes of conflicts (Bahasa Malaysia)
What are the causes of conflicts (Bahasa Malaysia)What are the causes of conflicts (Bahasa Malaysia)
What are the causes of conflicts (Bahasa Malaysia)
alish sha
 
Rèdais & IED_Gokcek
Rèdais & IED_GokcekRèdais & IED_Gokcek
Rèdais & IED_Gokcek
Rèdais
 
15waystobehappierqnet 130925034933-phpapp02
15waystobehappierqnet 130925034933-phpapp0215waystobehappierqnet 130925034933-phpapp02
15waystobehappierqnet 130925034933-phpapp02
Nicky Yin
 
Metabolismo agueda
Metabolismo aguedaMetabolismo agueda
Metabolismo aguedajuanapardo
 
Transcricion e traducion new
Transcricion e traducion newTranscricion e traducion new
Transcricion e traducion newjuanapardo
 

Viewers also liked (20)

2008 annualreport
2008 annualreport2008 annualreport
2008 annualreport
 
الرسم المظوري
الرسم المظوريالرسم المظوري
الرسم المظوري
 
External
ExternalExternal
External
 
Shrinkage Estimation of Linear Panel Data Models Under Nearly Singular Design
Shrinkage Estimation of Linear Panel Data Models Under Nearly Singular DesignShrinkage Estimation of Linear Panel Data Models Under Nearly Singular Design
Shrinkage Estimation of Linear Panel Data Models Under Nearly Singular Design
 
Ventajas y desventajas
Ventajas y desventajasVentajas y desventajas
Ventajas y desventajas
 
How to manage your home improvement projects
How to manage your home improvement projectsHow to manage your home improvement projects
How to manage your home improvement projects
 
Sistem Presensi Siswa Berbasis Barcode Scanner.
Sistem Presensi Siswa Berbasis Barcode Scanner.Sistem Presensi Siswa Berbasis Barcode Scanner.
Sistem Presensi Siswa Berbasis Barcode Scanner.
 
Ud 0 final juani
Ud 0 final juaniUd 0 final juani
Ud 0 final juani
 
A Design Thinking Approach to Online Engagement
A Design Thinking Approach to Online EngagementA Design Thinking Approach to Online Engagement
A Design Thinking Approach to Online Engagement
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5
 
Fotosíntese
FotosínteseFotosíntese
Fotosíntese
 
Investment presentation
Investment presentationInvestment presentation
Investment presentation
 
Celula mitose e_moiose new
Celula mitose e_moiose newCelula mitose e_moiose new
Celula mitose e_moiose new
 
The Secret Service Methods for Finding and Fixing Unexplainable Distributed S...
The Secret Service Methods for Finding and Fixing Unexplainable Distributed S...The Secret Service Methods for Finding and Fixing Unexplainable Distributed S...
The Secret Service Methods for Finding and Fixing Unexplainable Distributed S...
 
What are the causes of conflicts (Bahasa Malaysia)
What are the causes of conflicts (Bahasa Malaysia)What are the causes of conflicts (Bahasa Malaysia)
What are the causes of conflicts (Bahasa Malaysia)
 
Rèdais & IED_Gokcek
Rèdais & IED_GokcekRèdais & IED_Gokcek
Rèdais & IED_Gokcek
 
15waystobehappierqnet 130925034933-phpapp02
15waystobehappierqnet 130925034933-phpapp0215waystobehappierqnet 130925034933-phpapp02
15waystobehappierqnet 130925034933-phpapp02
 
Metabolismo agueda
Metabolismo aguedaMetabolismo agueda
Metabolismo agueda
 
Transcricion e traducion new
Transcricion e traducion newTranscricion e traducion new
Transcricion e traducion new
 
08 proteinas
08 proteinas08 proteinas
08 proteinas
 

Similar to Lab 10 sem ii_12_13

Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
Saket Pathak
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
C++ lab assignment
C++ lab assignmentC++ lab assignment
C++ lab assignment
Saket Pathak
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 sol
IIUM
 
Unit i intro-operators
Unit   i intro-operatorsUnit   i intro-operators
Unit i intro-operators
HINAPARVEENAlXC
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
josies1
 
Functions Practice Sheet.docx
Functions Practice Sheet.docxFunctions Practice Sheet.docx
Functions Practice Sheet.docx
SwatiMishra364461
 
Functions
FunctionsFunctions
Functions
Swarup Boro
 
C Programming Unit-4
C Programming Unit-4C Programming Unit-4
C Programming Unit-4
Vikram Nandini
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
ssuser3cbb4c
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
vandna123
 
Pointers
PointersPointers
C- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutionsC- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutions
Animesh Chaturvedi
 
Interesting facts on c
Interesting facts on cInteresting facts on c
Interesting facts on c
Durgadevi palani
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
nayakq
 
[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers
Muhammad Hammad Waseem
 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
alish sha
 
pointers 1
pointers 1pointers 1
pointers 1
gaurav koriya
 

Similar to Lab 10 sem ii_12_13 (20)

Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
C++ lab assignment
C++ lab assignmentC++ lab assignment
C++ lab assignment
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 sol
 
Unit i intro-operators
Unit   i intro-operatorsUnit   i intro-operators
Unit i intro-operators
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
 
Functions Practice Sheet.docx
Functions Practice Sheet.docxFunctions Practice Sheet.docx
Functions Practice Sheet.docx
 
Functions
FunctionsFunctions
Functions
 
C Programming Unit-4
C Programming Unit-4C Programming Unit-4
C Programming Unit-4
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
 
Pointers
PointersPointers
Pointers
 
C- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutionsC- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutions
 
Interesting facts on c
Interesting facts on cInteresting facts on c
Interesting facts on c
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
 
[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers
 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
Introduction to c part 2
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
 
pointers 1
pointers 1pointers 1
pointers 1
 

More from alish sha

T22016 – how to answer with ubs 9
T22016 – how to answer with ubs 9T22016 – how to answer with ubs 9
T22016 – how to answer with ubs 9
alish sha
 
July 2014 theory exam (theory)
July 2014 theory exam (theory)July 2014 theory exam (theory)
July 2014 theory exam (theory)
alish sha
 
Accounting basic equation
Accounting basic equation Accounting basic equation
Accounting basic equation
alish sha
 
It 302 computerized accounting (week 2) - sharifah
It 302   computerized accounting (week 2) - sharifahIt 302   computerized accounting (week 2) - sharifah
It 302 computerized accounting (week 2) - sharifah
alish sha
 
It 302 computerized accounting (week 1) - sharifah
It 302   computerized accounting (week 1) - sharifahIt 302   computerized accounting (week 1) - sharifah
It 302 computerized accounting (week 1) - sharifah
alish sha
 
Lab 5 2012/2012
Lab 5 2012/2012Lab 5 2012/2012
Lab 5 2012/2012
alish sha
 
Purpose elaborate
Purpose elaboratePurpose elaborate
Purpose elaborate
alish sha
 
Lab sheet 1
Lab sheet 1Lab sheet 1
Lab sheet 1
alish sha
 
Test 1 alish schema 1
Test 1 alish schema 1Test 1 alish schema 1
Test 1 alish schema 1
alish sha
 
Lab 6 sem ii_11_12
Lab 6 sem ii_11_12Lab 6 sem ii_11_12
Lab 6 sem ii_11_12
alish sha
 
Test 1 skema q&a
Test 1 skema q&aTest 1 skema q&a
Test 1 skema q&a
alish sha
 
Test 1 skema q&a
Test 1 skema q&aTest 1 skema q&a
Test 1 skema q&a
alish sha
 
Final project
Final projectFinal project
Final projectalish sha
 
Final project
Final projectFinal project
Final project
alish sha
 
Attn list test
Attn list testAttn list test
Attn list testalish sha
 
Carry markdam31303
Carry markdam31303Carry markdam31303
Carry markdam31303
alish sha
 
Final project
Final projectFinal project
Final project
alish sha
 
Final project
Final projectFinal project
Final project
alish sha
 
Dti2143 dam31303 lab sheet 8
Dti2143 dam31303 lab sheet 8Dti2143 dam31303 lab sheet 8
Dti2143 dam31303 lab sheet 8
alish sha
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
alish sha
 

More from alish sha (20)

T22016 – how to answer with ubs 9
T22016 – how to answer with ubs 9T22016 – how to answer with ubs 9
T22016 – how to answer with ubs 9
 
July 2014 theory exam (theory)
July 2014 theory exam (theory)July 2014 theory exam (theory)
July 2014 theory exam (theory)
 
Accounting basic equation
Accounting basic equation Accounting basic equation
Accounting basic equation
 
It 302 computerized accounting (week 2) - sharifah
It 302   computerized accounting (week 2) - sharifahIt 302   computerized accounting (week 2) - sharifah
It 302 computerized accounting (week 2) - sharifah
 
It 302 computerized accounting (week 1) - sharifah
It 302   computerized accounting (week 1) - sharifahIt 302   computerized accounting (week 1) - sharifah
It 302 computerized accounting (week 1) - sharifah
 
Lab 5 2012/2012
Lab 5 2012/2012Lab 5 2012/2012
Lab 5 2012/2012
 
Purpose elaborate
Purpose elaboratePurpose elaborate
Purpose elaborate
 
Lab sheet 1
Lab sheet 1Lab sheet 1
Lab sheet 1
 
Test 1 alish schema 1
Test 1 alish schema 1Test 1 alish schema 1
Test 1 alish schema 1
 
Lab 6 sem ii_11_12
Lab 6 sem ii_11_12Lab 6 sem ii_11_12
Lab 6 sem ii_11_12
 
Test 1 skema q&a
Test 1 skema q&aTest 1 skema q&a
Test 1 skema q&a
 
Test 1 skema q&a
Test 1 skema q&aTest 1 skema q&a
Test 1 skema q&a
 
Final project
Final projectFinal project
Final project
 
Final project
Final projectFinal project
Final project
 
Attn list test
Attn list testAttn list test
Attn list test
 
Carry markdam31303
Carry markdam31303Carry markdam31303
Carry markdam31303
 
Final project
Final projectFinal project
Final project
 
Final project
Final projectFinal project
Final project
 
Dti2143 dam31303 lab sheet 8
Dti2143 dam31303 lab sheet 8Dti2143 dam31303 lab sheet 8
Dti2143 dam31303 lab sheet 8
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
 

Lab 10 sem ii_12_13

  • 1. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI 10202: COMPUTER PROGRAMMING LAB 10 : Functions (cont) NAME : _____________________________________ MATRICS NO.: _______________ DATE : ____________ MARK Exercise 1: Type the coding below and answer the following questions: 1 #include<stdio.h> 2 #include<conio.h> 3 void swapByValue(int a, int b ); 4 void swapByAddress(int *a, int *b ); 5 6 void swapByValue(int a, int b ){ 7 int temp; 8 Temp = a; 9 a = b; 10 b = temp; 11 12 } 13 void swapByAddress(int *a, int *b ){ 14 int temp; 15 temp = *a; 16 *a = *b; 17 *b = temp; 18 19 } 20 int main(void){ 21 int a, b; 22 a = 8, b = 5; 23 24 printf("nIntially a=%3d and b=%3d ", a, b); 25 swapByValue(a, b); 26 printf("nAfter swap by value a=%3d and b=%3d", a, b); 27 swapByAddress(&a, &b); 28 printf("nAfter swap by address a=%3d and b=%3d", a, b); 29 getch(); 30 return 0; 31} i. What is the output of the coding? Output:
  • 2. ii. Explain the difference between passing by value and address By value: ________________________________________________________ ________________________________________________________________ ________________________________________________________________ By Address: ______________________________________________________ ________________________________________________________________ ________________________________________________________________ iii. Add printf("nnIn swap by value function a=%3d and b=%3d", a, b); at line 11 Add printf("nnIn swap by address a=%3d and b=%3d", *a, *b); at line 18 What is the output of the coding? Explain: By value: ________________________________________________________ ________________________________________________________________ ________________________________________________________________ By Address: ______________________________________________________ ________________________________________________________________ ________________________________________________________________
  • 3. Exercise 2 : Type the coding below and answer the following questions: #include <stdio.h> #include <conio.h> main () { int n; long faktorial ( int ); printf("Enter n (1-15): "); scanf ("%d",&n); printf ("%d! = %dn",n, faktorial ( n ) ); getch(); } long faktorial ( int n ) { if ( n == 0 ) return 1; else return (n * faktorial ( n -1 )); } i. What is the output of the coding? Output: ii. Explain how the coding work (input: 3) : ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________