18
Functions in C Language

Functions in c

Embed Size (px)

Citation preview

Page 1: Functions in c

Functions in C Language

Page 2: Functions in c

main()

1कोणत्याही सी प्रोगॅ्रम मध्ये एक मेन फंक्शन असतेच

Page 3: Functions in c

main()

12 3कोणत्याही सी प्रोग्रॅम मध्ये एका पेक्षा जास्त फंक्शन

असतील तरी मेन फंक्शन एकच असते

Page 4: Functions in c

main()

12 3प्रोगॅ्रमचे एग्झि !क्युशन कायम मेन फंक्शन पासुन होते

Page 5: Functions in c

main()

1

कोणतेही फंक्शन हे कोणतेही फंक्शन कॉल करु शकते

Page 6: Functions in c

main()

1x

y

x is actual argument

y is formal argument2

Page 7: Functions in c

y

x 5

5

Page 8: Functions in c

voidintfloat

Page 9: Functions in c
Page 10: Functions in c
Page 11: Functions in c
Page 12: Functions in c

#include<stdio.h>#include<conio.h>int maxint(int,int); // prototype of the functionint main(){

int x, y;int max;clrscr();

printf(“Enter 2 numbers\n”);scanf(“%d%d”,&x,&q\y);max = maxint(x,y); // function callprintf(“Largest number is %d\n”,max);

getch();}int maxint(int p, int q){

if(p>q)return p;

elsereturn q;

}

Page 13: Functions in c
Page 14: Functions in c

#include<stdio.h>#include<conio.h>int maxint(int,int); // prototype of the functionint main(){

int x, y;int max;clrscr();

printf(“Enter 2 numbers\n”);scanf(“%d%d”,&x,&q);

int maxint(int x, int x){

if(x>y)return x;

elsereturn y;

}

getch();}

One function block inside other function block

Page 15: Functions in c

#include<stdio.h>#include<conio.h>int maxint(int,int); // prototype of the functionint main(){

int x, y;int max;clrscr();

printf(“Enter 2 numbers\n”);scanf(“%d%d”,&x,&q\y);max = maxint(x,y); // function callprintf(“Largest number is %d\n”,max);

getch();}int maxint(int p, int q){

if(p>q)return p;

elsereturn q;

}

Page 16: Functions in c

#include<stdio.h>#include<conio.h>int maxint(int,int); // prototype of the functionint main(){

int x, y;int max;clrscr();

printf(“Enter 2 numbers\n”);scanf(“%d%d”,&x,&q\y);max = maxint(x,y); // function callprintf(“Largest number is %d\n”,max);

getch();}int maxint(int p, int q){

if(p>q)return (p);

elsereturn q;

}

Page 17: Functions in c

Factorial value

n! = n * n-1 * n-2 * n-3 * n-4……..

5! = 5 * 4 * 3 * 2 * 15! = 120

Page 18: Functions in c

#include<stdio.h>#include<conio.h>void main(){

int number;int fact;clrscr();

printf(“Enter Number\t”);scanf(“%d”,&number);

fact = factorial(number);printf(“%d! = %d\n”,number,fact);getch();

}int factorial(int x){

int i;int f = 1;for(i=x; i >= 1; i--){

f = f * i;} return f;

}

Return type Formal argument

5! = 5 * 4 * 3 * 2 * 1

5 1

x