Presented By:- RUPENDRA  CHOUDHARY B.Tech.- 2 nd  YEAR (CSE) E.C.B. ,BIKANER FUNCTION IN ‘C’
A function is a block of code that perform special task of some kind. WHAT IS FUNCTION?
WHY WE USE FUNCTION? <ul><li>main() </li></ul><ul><li>{ </li></ul><ul><li>int i; </li></ul><ul><li>printf(“computer scienc...
C:function.c <ul><li>void function(int x,char y) </li></ul><ul><li>{ </li></ul><ul><li>int i; </li></ul><ul><li>for(i=0;i<...
<ul><li>#include<c:function.c> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int i; </li></ul><ul><l...
PARTS OF FUNCTION <ul><li>1)-Declaration </li></ul><ul><li>2)-Calling </li></ul><ul><li>3)-Definition </li></ul>
DESCRIPTION <ul><li>int sum(int,int); </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int a,b,add; </l...
FUNCTION TYPES <ul><li>1)-No argument & No return value </li></ul><ul><li>2)-No argument & Having return value </li></ul><...
ILLUSTRATIONS <ul><li>1)-What will be output? </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int i=3,...
2)-What will be output? <ul><li>main() </li></ul><ul><li>{ </li></ul><ul><li>int a=5,b; </li></ul><ul><li>{ </li></ul><ul>...
3)-What will be output ? <ul><li>func(int i) </li></ul><ul><li>{ </li></ul><ul><li>if(i%2) </li></ul><ul><li>return 0; </l...
4)- What will be output? <ul><li>int max(int x,int y) </li></ul><ul><li>{ </li></ul><ul><li>return x>y?x:y; </li></ul><ul>...
5) -What will be  output? <ul><li>int *fun(); </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int *j; ...
6)-what will be output? <ul><li>void increment(); </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>incr...
7)-Will error occur? <ul><li>void display(); </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>goto labe...
Concept of return value <ul><li>void swap(int,int);  </li></ul><ul><li>void main()  </li></ul><ul><li>{ </li></ul><ul><li>...
Recursive function is a function which contains a call to itself RECURSIVE  FUNCTION
8)-What will be output? <ul><li>/* Based on stack */ </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>i...
DESCRIPTION <ul><li>int fact(int); </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int a=4; </li></ul>...
9)-Will error occur? <ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int n; </li></ul><ul><li>scanf(“%d”,n); </l...
10)-What will be output? <ul><li>int i=1; </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>if(i<=3) </l...
RECURSION  V/S  ITERATION <ul><li>Recursive solution is always logical and it is very difficult to trace. </li></ul><ul><l...
THANKS ANY QUERY….?
Upcoming SlideShare
Loading in...5
×

lets play with "c"..!!! :):)

568

Published on

hey this is Rupendra choudhary..!! i shared my "c" lang ppt..!!! u just goto that ppt if u r in deep with "c" ..!!! i create after i hv played a much with "c"..(sorry bt ppt is slightly disturbd may be due to unsupportable msppt2010 by slideshare)...find me on rupendrachoudhary1990@gmail.com or https://rupendrachoudhary.wordpress.com

Published in: Education, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
568
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
23
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "lets play with "c"..!!! :):)"

  1. 1. Presented By:- RUPENDRA CHOUDHARY B.Tech.- 2 nd YEAR (CSE) E.C.B. ,BIKANER FUNCTION IN ‘C’
  2. 2. A function is a block of code that perform special task of some kind. WHAT IS FUNCTION?
  3. 3. WHY WE USE FUNCTION? <ul><li>main() </li></ul><ul><li>{ </li></ul><ul><li>int i; </li></ul><ul><li>printf(“computer science n”); </li></ul><ul><li>for(i=0;i<20;i++) </li></ul><ul><li>{ </li></ul><ul><li>printf(“*”); </li></ul><ul><li>} </li></ul><ul><li>printf(“n engineering hobby n”); </li></ul><ul><li>for(i=0;i<10;i++) </li></ul><ul><li>{ </li></ul><ul><li>printf(“#”); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  4. 4. C:function.c <ul><li>void function(int x,char y) </li></ul><ul><li>{ </li></ul><ul><li>int i; </li></ul><ul><li>for(i=0;i<x;i++) </li></ul><ul><li>{ </li></ul><ul><li>printf(“%c”,y); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  5. 5. <ul><li>#include<c:function.c> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int i; </li></ul><ul><li>printf(“computer science’s runner n”); </li></ul><ul><li>function(20,’*’); </li></ul><ul><li>printf(“engineering is hobby n”); </li></ul><ul><li>function(10,’#’); </li></ul><ul><li>} </li></ul>
  6. 6. PARTS OF FUNCTION <ul><li>1)-Declaration </li></ul><ul><li>2)-Calling </li></ul><ul><li>3)-Definition </li></ul>
  7. 7. DESCRIPTION <ul><li>int sum(int,int); </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int a,b,add; </li></ul><ul><li>scanf(“%d%d”,&a,&b); </li></ul><ul><li>add=sum(a,b); </li></ul><ul><li>printf(“add is %d”,add); </li></ul><ul><li>} </li></ul><ul><li>int sum(int x,int y) </li></ul><ul><li>{ </li></ul><ul><li>return x+y; </li></ul><ul><li>} </li></ul>
  8. 8. FUNCTION TYPES <ul><li>1)-No argument & No return value </li></ul><ul><li>2)-No argument & Having return value </li></ul><ul><li>3)-Having argument & No return value </li></ul><ul><li>4)-Having argument & Return value </li></ul><ul><li>5)-Recursive function </li></ul>
  9. 9. ILLUSTRATIONS <ul><li>1)-What will be output? </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int i=3,r; </li></ul><ul><li>r=sizeof f(++i)+f(--i)+f(i-2); </li></ul><ul><li>printf(“%d%d”,r,i); </li></ul><ul><li>} </li></ul><ul><li>int f(int j) </li></ul><ul><li>{ </li></ul><ul><li>if(!!j) </li></ul><ul><li>return ++j; </li></ul><ul><li>else </li></ul><ul><li>return --j; </li></ul><ul><li>} </li></ul>
  10. 10. 2)-What will be output? <ul><li>main() </li></ul><ul><li>{ </li></ul><ul><li>int a=5,b; </li></ul><ul><li>{ </li></ul><ul><li>int b=10; </li></ul><ul><li>++b; </li></ul><ul><li>++a; </li></ul><ul><li>printf(“%d%dn”,a,b); </li></ul><ul><li>{ </li></ul><ul><li>int a=20; </li></ul><ul><li>++a; </li></ul><ul><li>a=++b; </li></ul><ul><li>printf(“%d%dn”,a,b); </li></ul><ul><li>} </li></ul><ul><li>++a; </li></ul><ul><li>++b; </li></ul><ul><li>Printf(“%d%dn”,a,b); </li></ul><ul><li>} </li></ul><ul><li>Printf(“%d%dn”,a,b); </li></ul><ul><li>} </li></ul>
  11. 11. 3)-What will be output ? <ul><li>func(int i) </li></ul><ul><li>{ </li></ul><ul><li>if(i%2) </li></ul><ul><li>return 0; </li></ul><ul><li>else </li></ul><ul><li>return 1; </li></ul><ul><li>} </li></ul><ul><li>main() </li></ul><ul><li>{ </li></ul><ul><li>int i=1; </li></ul><ul><li>i=func(i); </li></ul><ul><li>i=func(i); </li></ul><ul><li>printf(“%d”,i); </li></ul><ul><li>} </li></ul>
  12. 12. 4)- What will be output? <ul><li>int max(int x,int y) </li></ul><ul><li>{ </li></ul><ul><li>return x>y?x:y; </li></ul><ul><li>} </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int m; </li></ul><ul><li>m=max(max(4,max(11,6)),max(10,5)); </li></ul><ul><li>printf(“%d”,m); </li></ul><ul><li>} </li></ul>
  13. 13. 5) -What will be output? <ul><li>int *fun(); </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int *j; </li></ul><ul><li>j=fun(); </li></ul><ul><li>printf(“%d”,*j); </li></ul><ul><li>} </li></ul><ul><li>int *fun() </li></ul><ul><li>{ </li></ul><ul><li>int k=35; </li></ul><ul><li>return &k; </li></ul><ul><li>} </li></ul>
  14. 14. 6)-what will be output? <ul><li>void increment(); </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>increment(); </li></ul><ul><li>increment(); </li></ul><ul><li>} </li></ul><ul><li>void increment() </li></ul><ul><li>{ </li></ul><ul><li>auto int i=1; </li></ul><ul><li>printf(“%d”,i); </li></ul><ul><li>printf(“%d”,&i); </li></ul><ul><li>} </li></ul>
  15. 15. 7)-Will error occur? <ul><li>void display(); </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>goto label; </li></ul><ul><li>printf(“ecb alumni”); </li></ul><ul><li>} </li></ul><ul><li>void display() </li></ul><ul><li>{ </li></ul><ul><li>label: </li></ul><ul><li>printf(“computer science”); </li></ul><ul><li>} </li></ul>
  16. 16. Concept of return value <ul><li>void swap(int,int); </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int a=1,b=2; </li></ul><ul><li>swap(a,b); </li></ul><ul><li>printf(“%d%d”,a,b); </li></ul><ul><li>} </li></ul><ul><li>void swap(int x,int y) </li></ul><ul><li>{ </li></ul><ul><li>int t; </li></ul><ul><li>t=x; </li></ul><ul><li>x=y; </li></ul><ul><li>y=t; </li></ul><ul><li>printf(“%d%d”,x,y); </li></ul><ul><li>} </li></ul><ul><li>void swap(int*,int*); </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int a=1,b=2; </li></ul><ul><li>swap(&a,&b); </li></ul><ul><li>printf(“%d%d”,a,b); </li></ul><ul><li>} </li></ul><ul><li>void swap(int *x,int *y) </li></ul><ul><li>{ </li></ul><ul><li>int t; </li></ul><ul><li>t=*x; </li></ul><ul><li>*x=*y; </li></ul><ul><li>*y=t; </li></ul><ul><li>} </li></ul>
  17. 17. Recursive function is a function which contains a call to itself RECURSIVE FUNCTION
  18. 18. 8)-What will be output? <ul><li>/* Based on stack */ </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int a=1,b=2,c=3,d; </li></ul><ul><li>printf(“%d%d%d%d”); </li></ul><ul><li>} </li></ul>
  19. 19. DESCRIPTION <ul><li>int fact(int); </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int a=4; </li></ul><ul><li>result=fact(a); </li></ul><ul><li>printf(“factorial vauue is=%d”,result); </li></ul><ul><li>} </li></ul><ul><li>int fact(int x) </li></ul><ul><li>{ </li></ul><ul><li>if(x==1) </li></ul><ul><li>return 1; </li></ul><ul><li>else </li></ul><ul><li>return x*fact(x-1); </li></ul><ul><li>} </li></ul>
  20. 20. 9)-Will error occur? <ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int n; </li></ul><ul><li>scanf(“%d”,n); </li></ul><ul><li>printf(“%d”,fac()); </li></ul><ul><li>} </li></ul><ul><li>int fac(int n) </li></ul><ul><li>{ </li></ul><ul><li>if(x==0) </li></ul><ul><li>return 1; </li></ul><ul><li>else </li></ul><ul><li>return n*fac(n-1); </li></ul><ul><li>} </li></ul>
  21. 21. 10)-What will be output? <ul><li>int i=1; </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>if(i<=3) </li></ul><ul><li>{ </li></ul><ul><li>i++; </li></ul><ul><li>main(); </li></ul><ul><li>} </li></ul><ul><li>printf(“%d%d%d”,i,++i,i++); </li></ul><ul><li>} </li></ul>
  22. 22. RECURSION V/S ITERATION <ul><li>Recursive solution is always logical and it is very difficult to trace. </li></ul><ul><li>Recursion takes a lot of stack space. </li></ul><ul><li>Recursive calling increase the space complexity. </li></ul><ul><li>A recursive definition defines an object in simpler cases of itself reducing nested looping complexity. </li></ul><ul><li>Every recursive problem can be done by iteration but vice versa is not always true. </li></ul>
  23. 23. THANKS ANY QUERY….?
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×