Upcoming SlideShare
×

Function recap

1,032 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
1,032
On SlideShare
0
From Embeds
0
Number of Embeds
155
Actions
Shares
0
85
0
Likes
0
Embeds 0
No embeds

No notes for slide

Function recap

1. 1. Function Recap<br />
2. 2. What is function?<br />A function is a section of a program that performs a specific task .<br />Solving a problem using different functions makes programming much simpler with fewer defects .<br />It’s a solution for a big project that split into small sub project. <br />
3. 3. Common Type (FUNCTION)<br />Void function Without argument<br />Void unction With Input argument<br />Function with input argument and single result<br />
4. 4. Void function without argument syntax: void functionname(void)<br />Example:<br />display()<br />draw_circle()<br />draw_triangle()<br />The nearest explantion is printf()<br />
5. 5. Void function without argument<br />void draw_triangle(void){<br />introw,space,star;<br />for(row=1;row<=9;row++)<br />{ <br /> for(space=8;space>=row;space--)<br /> {<br />printf("%c",288); <br /> }; <br /> for (star=1;star<row;star++)<br /> {<br />printf("* "); } <br />printf("n");<br />} <br />}<br />
6. 6. Why void? (most common seen in function without argument)<br />Void is use when the function does not return any value<br />More explanation:<br />The subfunction is called draw_triangle()<br />from the main function but the function prototype is written as void draw_triangle(void)<br />
7. 7. Void function with input argument<br />syntax:functiontypefunctionname(input)<br />Example:<br />double box(123.45)<br />circumference(5.0)<br />calculate(inum1)<br />
8. 8. Void function with input argument<br />void box(double num){<br />printf("***********n");<br />printf("* *n");<br />printf("* *n");<br />printf("* %7.2f *n",num);<br />printf("* *n");<br />printf("* *n");<br />printf("***********");<br />}<br />
9. 9. #include<stdio.h><br />#include<conio.h><br />void box(double num){<br />printf("***********n");<br />printf("* *n");<br />printf("* *n");<br />printf("* %7.2f *n",num);<br />printf("* *n");<br />printf("* *n");<br />printf("***********");<br />}<br />int main(){ <br />box(123.45);<br />getch();<br />return 0; <br />}<br />
10. 10. VOID>> and what is the different between both function shown<br />void box(double num)<br />void draw_triangle(void)<br />
11. 11. Function with input argument and single result<br />syntax: <br />functiontypefunctinname(input argument)<br />Example:<br />double circumferencecal(intrads);<br />
12. 12. Function with input argument and single result<br />#include<stdio.h><br />#include<conio.h><br />double circumferencecal(intrads);<br />intmain(){<br />intrads=5; double circum; <br /> circum=circumferencecal(rads);<br />printf("Ukurlilitbagibulatanbagiber-radius-kan %d adalah %.4lf",rads,circum); <br />getch();<br /> return 0;<br /> }<br />double circumferencecal(intrads){<br /> double x;<br /> float pi=3.1415;<br /> x=2*pi*rads;<br /> return(x);<br /> }<br />
13. 13. Returning values<br /><ul><li>The result of the function can be given back to the calling functions
14. 14. Return statement is used to return a value to the calling function
15. 15. Syntax:</li></ul>return (expression) ;<br /><ul><li>Example:</li></ul>return(iNumber * iNumber); <br /> return 0;<br /> return (3);<br /> return;<br /> return (10 * i);<br />
16. 16. Function with multiple arguments<br />Syntax: <br />functionname(argument1,argument2)<br />Example:<br />circumferencecal(radian,PI);<br />
18. 18. Chotto complicated example<br />#include<stdio.h><br />#include<conio.h><br />#include<math.h><br /> double circumferencecal(intrads,double PI){<br /> double x;<br /> x=2*PI*rads;<br /> return(x);<br /> }<br /> double areacal(intrads,double PI){ <br /> double y;<br /> y=PI*pow(rads,2);<br /> return(y);<br /> }<br />int main(){<br />intrads=5; double area,circum,PI=3.1415; <br /> circum=circumferencecal(rads,PI);<br /> area=areacal(rads,PI); <br />printf("Ukurlilitbagibulatanbagiber-radius-kan %d adalah: %.4lfnManakalaluasnya pula: %.4lf",rads,circum,area);<br />getch();<br /> return 0;<br /> }<br />
19. 19. Do and Don’t in Function<br />
20. 20. GOTO<br />
21. 21. GO TO<br />Is a function in programming c that allows you to jump according to designation labels<br />Syntax:<br />gotolabel;<br />Just simply means to redirect you to the label located in the coding<br />label: <br />Just simply means to redirect you to the label<br />
22. 22. Example<br />