c programming function

17
C - PROGRAMMING FUNCTION

Upload: argusacademy

Post on 11-Jul-2015

138 views

Category:

Education


0 download

TRANSCRIPT

Page 1: C  programming function

C- PROGRAMMING FUNCTION

Page 2: C  programming function

NOTES

Page 3: C  programming function

System Define function#include<stdio.h>#include<conio.h>#include<math.h>void main(){

int num;float r;clrscr();printf(“Enter any no\n”);scanf(“%d”,&num);r=sqrt(num);printf(“root of %d is %f \n”, num,r);getch();

}

EXTRA

Page 4: C  programming function

NOTES

Page 5: C  programming function

NOTES

Page 6: C  programming function

User Define FunctionParameter and no return value#include<stdio.h>

#include<conio.h>void add(int, int);void main(){

int a,b;clrscr();printf(“Enter two number\n”);scanf(“%d%d”,&a,&b);printf(“Value of A =%d\n”,a);printf(“Value of B =%d\n”,b);add(a,b);getch();

} no return void add(int x, int y) { with Parameter

int z;z=x+y;printf(“Sum of two no = %d\n”,z);

}

EXTRA

Page 7: C  programming function

User Define FunctionParameter and return value#include<stdio.h>

#include<conio.h>int add(int, int);void main(){

int a,b,c;clrscr();printf(“Enter two number\n”);scanf(“%d%d”,&a,&b);printf(“Value of A =%d\n”,a);printf(“Value of B =%d\n”,b);c=add(a,b);printf(“Sum of two no = %d\n”,c);getch();

} with return int add(int x, int y){ with parameter

int z;z=x+y;return z;

}

EXTRA

Page 8: C  programming function

User Define FunctionNo Parameter and no return value#include<stdio.h>

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

clrscr();disp();getch();

} no return void disp(){ no parameter

int a,b,c;printf(“Enter two number\n”);scanf(“%d%d”,&a,&b);printf(“Value of A =%d\n”,a);printf(“Value of B =%d\n”,b);c=a+b;printf(“Sum of two no = %d\n”,c);getch();

}

EXTRA

Page 9: C  programming function

User Define FunctionNo Parameter and return value

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

clrscr();printf("Factorial %d",fact());getch();

} with return int fact(){ no parameter

int n,f=1;printf(" Enter any number\n");scanf("%d",&n);while(n>=1){

f=n*f;n--;

}return f;

}

EXTRA

Page 10: C  programming function

User Define FunctionCall by value method

#include<stdio.h>#include<conio.h>void disp (int , int);void main(){

int a,b;clrscr();printf(“Enter the Value of a & b\n”);scanf(“%d%d”,&a,&b);printf(“Value of a before function %d\n”,a);printf(“Value of b before function %d\n”,b);disp(a,b);printf(“value of a after function %d\n”,a);printf(“Value of b after function %d\n”,b);getch();

}void disp(int a, int b) {

a=a+10;b=b+10;printf(“Value of a inside function %d\n”,a);printf(“value of b inside function %d\n”,b);

}

EXTRA

Page 11: C  programming function

User Define FunctionCall by reference method

#include<stdio.h>#include<conio.h>void disp (int &, int&);void main(){

int a,b;clrscr();printf(“Enter the Value of a & b\n”);scanf(“%d%d”,&a,&b);printf(“Value of a before function %d\n”,a);printf(“Value of b before function %d\n”,b);disp(a,b);printf(“value of a after function %d\n”,a);printf(“Value of b after function %d\n”,b);getch();

}void disp(int &a, int &b) {

a=a+10;b=b+10;printf(“Value of a inside function %d\n”,a);printf(“value of b inside function %d\n”,b);

}

EXTRA

Page 12: C  programming function

NOTES

Page 13: C  programming function

EXTRA

Page 14: C  programming function

EXTRA

Page 15: C  programming function

EXTRA

Page 16: C  programming function

EXTRA

Page 17: C  programming function

#include<stdio.h>#include<conio.h>int table(int,int);void main(){

int n,y=1,t;clrscr();printf("Enter any no\n");scanf("%d",&n);table(n,y);getch();

}int table(int n, int y){ int t;

if(y==11){

return 0;}else{ t=n*y;

printf("%d*%d=%d\n",n,y,t);table(n,y+1);

}return t;

}

EXTRA