Upload
argusacademy
View
134
Download
0
Tags:
Embed Size (px)
Citation preview
C- PROGRAMMING FUNCTION
NOTES
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
NOTES
NOTES
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
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
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
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
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
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
NOTES
EXTRA
EXTRA
EXTRA
EXTRA
#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