Function As Subprogram and Modular Programming
Function As Subprogram and Modular Programming
FUNCTION
It refers to the section of a program that performs a specific task. The task assigned to a function is performed whenever Turbo C encounters the function name. It is also a subprogram (subroutine) that performs specific tasks
Syntax
datatype functionname(parameter variables) { variable declarations; statements; return }
2. Program defined functions Void The keyword void indicates that the method does not return any value
Problem 1. design a function-oriented program that performs a printing: OFFICIAL RECEIPT. Call or invoke this function from the main program twice.
#include<stdio.h> #include<conio.h> #include<string.h> void asterisk(void); main(){ clrscr(); textcolor(WHITE+BLINK); asterisk(); gotoxy(30,3);printf(OFFICI AL RECEIPT); asterisk(); getch();} void asterisk(void){ textcolor(YELLOW); printf(\n0000000000000 000000000000000000000 000000000000000000000 000000000000000000000 0000); return 0;}
Problem 2. design a function-oriented program that passes the value of the parameter test. The function multiplies test by 5 and displays the result according to the format %3.1lf. #include<stdio.h> double mainvar; void test (testvar) double testvar;{ testvar*=5; printf(%3.1lf\n,testvar);} main(){
Problem 3. Design a function-oriented program that emulates the sqr() function of Turbo C Programming language. Display the square root values of the input of n by the user.
#include<stdio.h> #include<math.h> int sqr(int number); main(){ int fav; clrscr(); printf(\n Supply your favorite numer:); scanf(%d,&fav); printf(\n The square value:%d,sqr(fav));
printf(\n The square root value:%f,sqrt(fav)); getch(); } int sqr(int number) { int mel; mel=numer*number; return mel; }
Program 4. Design a function-oriented program to convert the input dollar into its equivalent peso. Assume that US$1 is equivalent to PHP55.75.
#include<stdio.h> float dollar2peso(int mel); main() { int dollar; clrscr(); printf(\n How much your dollar to convert:); scanf(%d,&dollar); printf(\The peso equivalent/conversion is: %.2f,dollar2peso(dollar)); getch(); } float dollar2peso(int mel) { float dol2pes; dol2pes=55.75*mel; return dol2pes; }
#include<stdio.h> long fibonacci(int melo); main(){ int numb; clrscr(); printf(\n Supply number:); scanf(%d,&numb); fibonacci(numb); getch();} long fibonacci(int melo){ long m,me,mel,mels; mel=1;
mels=1; me=1; for(m=1;m<=melo;m++){ printf(%d ,me); if(m>=2){ me=mel+mels; mels=mel; mel=me;} delay(1000000);} return 0; }
Design a function-oriented program to compute the area of a circle. Use the formula: A=pi*r2
Design a function-oriented program that generates the Fibonacci series numbers of n as by user input. Display them in series. Example: Input Number:5 Fibonacci series: 1 1 2 3 5