SlideShare a Scribd company logo
left0UNIVERSITI TUN HUSSEIN ONN MALAYSIA<br />FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING <br />DTI 2143: COMPUTER PROGRAMMING<br />LAB EXERCISE 9 RECURSIVE and All-round  Recap<br />Exercise 1.0:  Compile and run the program below<br /># include<stdio.h><br /># include<conio.h><br />void recursiveFunction(int num) {<br />   if (num < 4)<br />      recursiveFunction(num + 1);<br />   printf(\"
%d\n\"
, num);<br />}<br />int main()<br />{<br />    int x = 2;<br />    recursiveFunction(x);<br />    <br />getch();<br />return 0;<br />}<br />Explain how the calculation work
Edit the coding so that the value of x is keyed in my the userExercise 2.0:  Compile and run the program below<br /># include<stdio.h><br /># include<conio.h><br />int factorial(unsigned int number)<br />{<br />    if(number <= 1)<br />        return 1;<br />    return number * factorial(number - 1);<br />}<br />int main()<br />{<br />    int x = 5;<br />    printf(\"
factorial of %d is %d\"
,x,factorial(x));<br />getch();<br />return 0;<br />}<br />Explain how the calculation work

More Related Content

DOCX
Bti1022 lab sheet 9 10
DOCX
Dam31303 dti2143 lab sheet 7
PDF
Bcsl 033 data and file structures lab s2-2
PDF
Prime number program in c
PDF
PDF
Bcsl 033 data and file structures lab s2-1
PDF
Bcsl 033 data and file structures lab s3-3
PDF
Bcsl 033 data and file structures lab s5-3
Bti1022 lab sheet 9 10
Dam31303 dti2143 lab sheet 7
Bcsl 033 data and file structures lab s2-2
Prime number program in c
Bcsl 033 data and file structures lab s2-1
Bcsl 033 data and file structures lab s3-3
Bcsl 033 data and file structures lab s5-3

What's hot (16)

PDF
Implement a queue using two stacks.
PDF
Bcsl 033 data and file structures lab s2-3
PDF
Bcsl 033 data and file structures lab s1-3
DOCX
1 (1)
PDF
Program in ‘C’ language to implement linear search using pointers
DOCX
C Language Programs
PPTX
C Programming Example
DOCX
Binary addition using class concept in c++
PDF
Bcsl 033 data and file structures lab s3-2
PDF
C Programming Example
PDF
Bcsl 033 data and file structures lab s5-2
PDF
Bcsl 033 data and file structures lab s3-1
PDF
Bcsl 033 data and file structures lab s1-1
PPTX
C programming codes for the class assignment
PDF
Progr2
Implement a queue using two stacks.
Bcsl 033 data and file structures lab s2-3
Bcsl 033 data and file structures lab s1-3
1 (1)
Program in ‘C’ language to implement linear search using pointers
C Language Programs
C Programming Example
Binary addition using class concept in c++
Bcsl 033 data and file structures lab s3-2
C Programming Example
Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s3-1
Bcsl 033 data and file structures lab s1-1
C programming codes for the class assignment
Progr2
Ad

Viewers also liked (20)

DOCX
Dti2143 dam31303 lab sheet 8
DOCX
Purpose elaborate
PPTX
Dti2143 chapter 3 arithmatic relation-logicalexpression
DOCX
Dti2143 lab sheet 6
DOCX
Lab exe 2 bti1022
PPTX
Chapter 3 dti2143
PPTX
Dti2143 chap 4 control structures aka_selection
DOCX
Bti1022 lab sheet 5
PPTX
Chap 2 input output dti2143
DOCX
Dti2143 lab sheet 6
PDF
Test 1 skema q&a
DOC
Effective treatment for learning disability at homeopathic clinic, Mumbai
PDF
Chapter1 6
PPTX
Dti2143 chap 4 control statement part 2
DOCX
Final project
DOCX
Test2
PPTX
Dti2143 chapter 5
DOC
Final project
DOCX
Lab exe 2 dti 2143
PPTX
Dti2143 chap 4 control structures aka_selection
Dti2143 dam31303 lab sheet 8
Purpose elaborate
Dti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 lab sheet 6
Lab exe 2 bti1022
Chapter 3 dti2143
Dti2143 chap 4 control structures aka_selection
Bti1022 lab sheet 5
Chap 2 input output dti2143
Dti2143 lab sheet 6
Test 1 skema q&a
Effective treatment for learning disability at homeopathic clinic, Mumbai
Chapter1 6
Dti2143 chap 4 control statement part 2
Final project
Test2
Dti2143 chapter 5
Final project
Lab exe 2 dti 2143
Dti2143 chap 4 control structures aka_selection
Ad

Similar to Dti2143 lab sheet 9 (20)

DOCX
Bti1022 lab sheet 3
PPTX
luckfuckfunctioneekefkfejewnfiwnfnenf.pptx
DOCX
Muzzammilrashid
DOCX
Qust & ans inc
DOCX
Core programming in c
DOCX
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
DOCX
In C Programming create a program that converts a number from decimal.docx
PDF
Common problems solving using c
DOCX
Dti2143 lab sheet 8
DOCX
Report on Flutter.docx prasentation for study
PPTX
Unit-IV.pptx
DOCX
PPTX
C Language Programming Introduction Lecture
PDF
7 functions
DOC
Programming egs
DOCX
DOCX
B.Com 1year Lab programs
PPTX
C decision making and looping.
DOCX
Here is the grading matrix where the TA will leave feedback. If you .docx
Bti1022 lab sheet 3
luckfuckfunctioneekefkfejewnfiwnfnenf.pptx
Muzzammilrashid
Qust & ans inc
Core programming in c
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
In C Programming create a program that converts a number from decimal.docx
Common problems solving using c
Dti2143 lab sheet 8
Report on Flutter.docx prasentation for study
Unit-IV.pptx
C Language Programming Introduction Lecture
7 functions
Programming egs
B.Com 1year Lab programs
C decision making and looping.
Here is the grading matrix where the TA will leave feedback. If you .docx

More from alish sha (20)

PPTX
T22016 – how to answer with ubs 9
PPTX
July 2014 theory exam (theory)
PPTX
Accounting basic equation
PPTX
It 302 computerized accounting (week 2) - sharifah
PPTX
It 302 computerized accounting (week 1) - sharifah
PPTX
What are the causes of conflicts (Bahasa Malaysia)
DOC
Lab 9 sem ii_12_13
DOCX
Lab 10 sem ii_12_13
DOC
Lab 6
DOC
Lab 5 2012/2012
DOC
Lab sheet 1
DOC
Test 1 alish schema 1
DOC
Lab 6 sem ii_11_12
PDF
Test 1 skema q&a
XLS
Attn list test
PDF
Carry markdam31303
DOCX
Final project
DOCX
Final project
PPT
Math hquickissential
DOCX
Dti2143 dam31303 lab sheet 5
T22016 – how to answer with ubs 9
July 2014 theory exam (theory)
Accounting basic equation
It 302 computerized accounting (week 2) - sharifah
It 302 computerized accounting (week 1) - sharifah
What are the causes of conflicts (Bahasa Malaysia)
Lab 9 sem ii_12_13
Lab 10 sem ii_12_13
Lab 6
Lab 5 2012/2012
Lab sheet 1
Test 1 alish schema 1
Lab 6 sem ii_11_12
Test 1 skema q&a
Attn list test
Carry markdam31303
Final project
Final project
Math hquickissential
Dti2143 dam31303 lab sheet 5

Dti2143 lab sheet 9

  • 1. left0UNIVERSITI TUN HUSSEIN ONN MALAYSIA<br />FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING <br />DTI 2143: COMPUTER PROGRAMMING<br />LAB EXERCISE 9 RECURSIVE and All-round Recap<br />Exercise 1.0: Compile and run the program below<br /># include<stdio.h><br /># include<conio.h><br />void recursiveFunction(int num) {<br /> if (num < 4)<br /> recursiveFunction(num + 1);<br /> printf(\" %d\n\" , num);<br />}<br />int main()<br />{<br /> int x = 2;<br /> recursiveFunction(x);<br /> <br />getch();<br />return 0;<br />}<br />Explain how the calculation work
  • 2. Edit the coding so that the value of x is keyed in my the userExercise 2.0: Compile and run the program below<br /># include<stdio.h><br /># include<conio.h><br />int factorial(unsigned int number)<br />{<br /> if(number <= 1)<br /> return 1;<br /> return number * factorial(number - 1);<br />}<br />int main()<br />{<br /> int x = 5;<br /> printf(\" factorial of %d is %d\" ,x,factorial(x));<br />getch();<br />return 0;<br />}<br />Explain how the calculation work
  • 3. Edit the coding so that the value of x is keyed in my the userExercise 3.0: Compile and run the program below<br />int main(){int x,y=0; printf(\" Masukkan sebarang nombor \" );scanf(\" %d\" ,&x); <br />while ( y <x){printf( \" %d\n\" , y );y++; }<br />getchar();}<br />Complete the coding
  • 4. Modify while to do-while loop
  • 5. Modify the while loop to for loopExercise 4.0: Compile and run the program below<br />printf(\" Enter an integer to choose a color(red=1,green=2,blue=3):\n\" );scanf(\" %d\" ,&color);switch(color){case 1: printf(\" you chose red color\n\" ); break;case 2:printf(\" you chose green color\n\" ); break;case 3:printf(\" you chose blue color\n\" ); break;default:printf(\" you did not choose any color\n\" );}<br />Complete the coding
  • 6. Modify the switch case to if else selectionExercise 5.0: Compile and run the program below<br /> double circumferencecal(int rads){<br /> double x;<br /> float pi=3.1415;<br /> x=2*pi*rads;<br /> return(x);<br /> }<br />Complete the coding