1 TOPICS TO DISCUSS : FUNCTIONS TYPES OF FUNCTIONS HEADER FILES PRESENTED BY : AVISHEK MAJUMDAR(837837) GUNJAN AGARWAL(856587) SATYAPRIYA DEY(856624)

Slides:



Advertisements
Similar presentations
Week 4 – Functions Introduction. Functions: Purpose Breaking a large problem into a series of smaller problems is a common problem- solving technique.
Advertisements

BBS514 Structured Programming (Yapısal Programlama)1 Functions and Structured Programming.
Fungsi Risanuri Hidayat, Ir., M.Sc.. Functions C usually consist of two things: instance variables and functions. All C programs consist of one or more.
Functions Quick Review What is a Function? A module of code that performs a specific job. Examples: Function that determines the maximum of two numbers.
Functions Definition: Instruction block called by name Good design: Each function should perform one task and do it well Functions are the basic building.
TK1913-C Programming1 TK1913-C Programming 1 C Library Functions C provides a collection of library functions for programmers If these library functions.
Basic Input/Output and Variables Ethan Cerami New York
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Functions in C. Function Terminology Identifier scope Function declaration, definition, and use Parameters and arguments Parameter order, number, and.
 Introduction Introduction  Types of Function Types of Function  Library function Library function  User defined function User defined function 
Computer Science 210 Computer Organization Introduction to C.
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
C Programming Tutorial – Part I CS Introduction to Operating Systems.
Reading the data from the input devices and displaying the results on the screen are the two main tasks of any program. To perform these tasks user friendly.
CMSC 1041 Functions II Functions that return a value.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Functions (1)
CSCI 171 Presentation 8 Built-in Functions, Preprocessor Directives, and Macros.
UniMAP SemI-09/10EKT120: Computer Programming1 Week 5 – Functions (1)
CECS 130 EXAM 1. To declare a constant (read only) value: const int x = 20; const float PI = 3.14; Can we do this? const int x;
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
GUJARAT KNOWLEDGE VILLAGE Faculty Name:- Prof H.M.Patel Students Name:- SONI VISHAL THAKKER BHAVIN ZALA JAYDIP ZALA.
Lecture-3 Functions and Recursion. C Preprocessor Includes header files like stdio.h Expands macros defined Handles conditional compilations PreprocessorProcessor.
Week 1 Lecture 2SE1SA51 Introducing C SE1SA5 Sue Walmsley.
Functions Chapter 5. Function A set of instructions that are designed to perform specific task. A complete and independent program. It is executed by.
NOTE: C programs consist of functions one of which must be main. C programs consist of functions one of which must be main. Every C program begins executing.
UMBC CMSC 104 – Section 01, Fall 2016
Arithmetic Expressions
EKT120: Computer Programming
Computer Science 210 Computer Organization
Formatted Input/Output
INC 161 , CPE 100 Computer Programming
presented BY : DURGESH KKHANDEKAR 1st semester
ECE Application Programming
CS1010 Discussion Group 11 Week 4 – Overview of C programming.
Functions, Part 2 of 2 Topics Functions That Return a Value
C Programming Tutorial – Part I
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
PGT 106: Computer Programming
Week 5 – Functions (1) EKT120: Computer Programming.
Programming Fundamentals Lecture #7 Functions
EKT120: Computer Programming
Functions in C Mrs. Chitra M. Gaikwad.
Formatted Input/Output
2008/11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park
Visit for more Learning Resources
Computer Science 210 Computer Organization
Functions Declarations CSCI 230
CSI-121 Structured Programming Language Lecture 14 Functions (Part 2)
Functions I Creating a programming with small logical units of code.
مباني كامپيوتر و برنامه سازي
CSCE 206 Lab Structured Programming in C
Functions, Part 1 of 3 Topics Using Predefined Functions
بنام خدا زبان برنامه نویسی C (21814( Lecture 4 Chapter 5
Functions, Part 2 of 3 Topics Functions That Return a Value
Assignment Operators Topics Increment and Decrement Operators
Assignment Operators Topics Increment and Decrement Operators
Functions, Part 1 of 3 Topics Using Predefined Functions
Introduction to C Programming
Introduction to Problem Solving and Programming
C – Programming Language
CSCE 206 Lab Structured Programming in C
Functions, Part 1 of 3 Topics Using Predefined Functions
Course Outcomes of Programming In C (PIC) (17212, C203):
Functions I Creating a programming with small logical units of code.
Assignment Operators Topics Increment and Decrement Operators
Functions, Part 2 of 3 Topics Functions That Return a Value
Functions, Part 2 of 3 Topics Functions That Return a Value
Presentation transcript:

1 TOPICS TO DISCUSS : FUNCTIONS TYPES OF FUNCTIONS HEADER FILES PRESENTED BY : AVISHEK MAJUMDAR(837837) GUNJAN AGARWAL(856587) SATYAPRIYA DEY(856624)

2 FUNCTION C Functions are a set of instructions enclosed by “{ }” which performs specific operations in a C program. The advantage of using function is to avoid rewriting of of same code and logic. There are 3 aspects in each C function: 1.Function declaration or prototype 2.Function call 3.Function definition

3 #include float sum ( float x,float y ); // Function declaration int main( ) // main function { float a,b, s; printf ( "\n Enter two numbers” \n"); scanf ( "%f%f", &a,&b ); s=add(a,b); // Function call printf ( "\nThe Sum of two numbers are %f ",s ); } float sum ( float x,float y ) // Function definition { float p; p = x +y; return p; } EXAMPLE OF FUNCTIONS

4 CONTINUED.... CALL BY VALUE The value of the variable is passed to the function. float square ( float x ); int main( ) { float m, n; printf ( "\n Enter a number for finding the square \n"); scanf ( "%f", &m ); n = square ( m ); printf ( "\n Square of the given number %f is %f",m,n ); } float square ( float x ) { float p; p = x * x; return p; } CALL BY REFERENCE The address of the variable is passed to the function void swap (int *x, int *y); int main( ) { int num1 = 5, num2 = 6; swap ( &num1, &num2 ); // function call printf ( "\n After swapping the values are %d and %d”, num1, num2 ); } void swap ( int *x, int *y ) { int temp; temp = *x; *x = *y; *y = temp;}

5 TYPES OF FUNCTION Functions are basically of two types: 1.Library Functions 2.User Defined Function LIBRARY FUNCTION: Library functions are the in-built functions in C Programming Language. Examples: main(), printf(), scanf()

6 TYPES OF User Defined FUNCTION Function can basically be categorized as: Function with arguments and return type- declaration:float calculate_area(int); definition: float calculate_area(int radius){ float area_of_circle; area_of_circle=3.14*radius*radius; return area_of_circle;} Function with arguments and without return type- declaration:void calculate_area(int); definition: void calculate_area(int radius){ float area_of_circle; area_of_circle=3.14*radius*radius; printf(“Area of the circle of radius-%d is-%d”,radius,area); }

7 Function without arguments and without return type - declaration:void calculate_area(); definition: void calculate_area(){ float area_of_circle,radius; printf(“Enter the value of radius”); scanf(“%f”,&radius); area_of_circle=3.14*radius*radius; printf(“Area of the circle of radius-%d is-%d”,radius,area);} Function without arguments and with return type - declaration:int calculate_area(); definition: int calculate_area(){ float area_of_circle,radius; printf(“Enter the value of radius”); scanf(“%f”,&radius); area_of_circle=3.14*radius*radius; return area_of_circle; }

8 printf() :formatted write scanf() :formatted read gets() :read string puts() :write string #include int main() { int number; printf("Enter an integer\n"); scanf("%d", &number); printf("Integer that you have entered is %d\n", number); return 0; } Header file is a file,containing C declarations and macro definitions to be shared between several source files. To use the header files in a program we have to include it,with the C preprocessing directive ‘#include’. A header file have extension.h. stdio.h What is Header files..

9 Header files serve two purposes. System header files declare the interfaces to parts of the operating system. I have to include them in program to supply the definitions and declarations. My own header files contain declarations for interfaces between the source files of programs. Each time I have a group of related declarations and macro definitions all or most of which are needed in several different source files, it is a good idea to create a header file for them.

10 Header files used in C.. stdio.h: Include all the input output function stdlib.h: include all the library function math.h : Include all the mathematical functions string.h: Include all string manipulation functions ctype.h: Include all character manipulating functions conio.h: Include all console input output functions stddef.h: Standard type definitions Time.h: Contains the C date and time operations

11