Create and Use FUNCTION in C Language:
(1) FUNCTION is a set of code that runs when it is called. In this blog, we will see how to create and called FUNCTION in C language.
(2) Advantage of creating FUNCTION is that they are reused. Means defining the code once and using FUNCTION many times.
(3) In C Language, there are Predefined functions such as MAIN(), PRINTF(), SCANF().
(4) Sample C language code and its output, as shown.
#include <stdio.h> #include <conio.h> // Creation of new function void myfirstfunction() { int x; x = 2; switch(x) { case 1: printf(“LOW”); break; case 2: printf(“Medium”); break; case 3: printf(“High”); break; } } int main() { myfirstfunction(); //call the function getch(); return 0; } |
(3) After that go to the “Build” menu and select the “Build” option for publishing the code as shown.
(4) After building the code, press the “Run” button, as shown.
(5) After pressing the “run” button, the output screen is opened, as shown.