0% found this document useful (0 votes)
261 views12 pages

Turbo C Function Programming Guide

This document discusses functions and modular programming in C. It defines a function as a section of code that performs a specific task. There are two types of functions: standard/built-in functions and programmer-defined functions. Functions provide advantages like modularity, reusability, and easier debugging. The document provides examples of function-oriented programs that perform tasks like printing a receipt, passing and returning values, calculating square roots, currency conversion, and computing the Fibonacci series.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
261 views12 pages

Turbo C Function Programming Guide

This document discusses functions and modular programming in C. It defines a function as a section of code that performs a specific task. There are two types of functions: standard/built-in functions and programmer-defined functions. Functions provide advantages like modularity, reusability, and easier debugging. The document provides examples of function-oriented programs that perform tasks like printing a receipt, passing and returning values, calculating square roots, currency conversion, and computing the Fibonacci series.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

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 }

Two Types of Function


1. Standard function These refer the predefined functions or built-in functions of the Turbo C system compiler. This kind of functions are numerous; in fact the majority of the statements used and applied in Turbo C programs are standard functions

2. Program defined functions Void The keyword void indicates that the method does not return any value

Advantages of using Functions


Functions fit naturally with a top-down approach. It can often be used more than once in a program and several other program s, thereby saving programming time. Using functions provides a natural method for dividing programming tasks among team programmers. Functions can be tested individually.

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(){

clrscr(); mainvar=5.0; printf(%3.1lf\n,mainvar); getche();}

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

You might also like