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

Dti2143 lab sheet 9

  • 1.
    left0UNIVERSITI TUN HUSSEINONN 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 codingso 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