KEMBAR78
Function recap | PPTX
Function Recap
What is function?A function is a section of a program that performs a specific task .Solving a problem using different functions makes programming much simpler with fewer defects .It’s a solution for a big project that split into small sub project.
Common Type (FUNCTION)Void function Without argumentVoid unction With Input argumentFunction with input argument and single result
Void function without argument syntax: void functionname(void)Example:display()draw_circle()draw_triangle()The nearest explantion is printf()
Void function without argumentvoid draw_triangle(void){introw,space,star;for(row=1;row<=9;row++){                           for(space=8;space>=row;space--)      {printf("%c",288);                                   };             for (star=1;star<row;star++)       {printf("* ");  }              printf("\n");}                                    }
Why void? (most common seen in function without argument)Void is use when the function does not return any valueMore explanation:The subfunction is called draw_triangle()from the main function but the function prototype is written as void draw_triangle(void)
Void function with input argumentsyntax:functiontypefunctionname(input)Example:double box(123.45)circumference(5.0)calculate(inum1)
Void function with input argumentvoid box(double num){printf("***********\n");printf("*         *\n");printf("*         *\n");printf("* %7.2f *\n",num);printf("*         *\n");printf("*         *\n");printf("***********");}
#include<stdio.h>#include<conio.h>void box(double num){printf("***********\n");printf("*         *\n");printf("*         *\n");printf("* %7.2f *\n",num);printf("*         *\n");printf("*         *\n");printf("***********");}int main(){   box(123.45);getch();return 0;  }
VOID>> and what is the different between both function shownvoid box(double num)void draw_triangle(void)
Function with input argument and single resultsyntax: functiontypefunctinname(input argument)Example:double circumferencecal(intrads);
Function with input argument and single result#include<stdio.h>#include<conio.h>double circumferencecal(intrads);intmain(){intrads=5;  double circum;     circum=circumferencecal(rads);printf("Ukurlilitbagibulatanbagiber-radius-kan %d adalah %.4lf",rads,circum);   getch();    return 0;    }double circumferencecal(intrads){           double x;           float pi=3.1415;           x=2*pi*rads;           return(x);           }
Returning valuesThe result of the function can be given back to the calling functions
Return statement is used to return a value to the calling function
Syntax:return (expression) ;Example:return(iNumber * iNumber);	      return 0;      return (3);      return;      return (10 * i);
Function with multiple argumentsSyntax:  functionname(argument1,argument2)Example:circumferencecal(radian,PI);
#include<stdio.h>#include<conio.h>double circumferencecal(intrads,double PI);int main(){intrads=5;  double circum,PI=3.1415;     circum=circumferencecal(rads,PI);printf("Ukurlilitbagibulatanbagiber-radius-kan %d adalah %.4lf",rads,circum);getch();    return 0;    }    double circumferencecal(intrads,double PI){           double x;                     x=2*PI*rads;           return(x);           }
Chotto complicated example#include<stdio.h>#include<conio.h>#include<math.h> double circumferencecal(intrads,double PI){           double x;           x=2*PI*rads;           return(x);           } double areacal(intrads,double PI){                      double y;           y=PI*pow(rads,2);           return(y);           }int main(){intrads=5;  double area,circum,PI=3.1415;         circum=circumferencecal(rads,PI);    area=areacal(rads,PI);  printf("Ukurlilitbagibulatanbagiber-radius-kan %d adalah: %.4lf\nManakalaluasnya pula: %.4lf",rads,circum,area);getch();    return 0;    }
Do and Don’t in Function
GOTO

Function recap

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