returntype FunctionName(datatype args1,datatype args2,...) { Statements --------------- return value ; }
#include⁢stdio.h> void star(int n) { int i; for( i=1 ; i <= n ; i++ ) printf("*"); } main() { star(25); printf("\n"); star(40); printf("\n"); star(15); }
************************* **************************************** **************
#include⁢stdio.h> void circle(int r) { float a,c; a=3.14*r*r; c=2*3.14*r; printf("Area is %f\n",a); printf("Circumference is %f",c); } main() { circle(5); }
Area is 78.500000 Circumference is 31.400000
#include⁢stdio.h> void even(int n) { int i; for(i=2;i<=n;i=i+2) printf("%d ",i); } main() { even(40); printf("\n"); even(25); printf("\n"); even(10); }
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 2 4 6 8 10 12 14 16 18 20 22 24 2 4 6 8 10
#include⁢stdio.h> void display(int a,int b) { int i; for(i=a;i<=b;i++) printf("%d ",i); } main() { display(10,20); printf("\n"); display(5,25); }
10 11 12 13 14 15 16 17 18 19 20 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#include⁢stdio.h> void interest(int p,float r,int n) { float si; si=p*r*n/100; printf("\nSimple Interest is %f",si); } main() { interest(5000,10.25,3); interest(25000,11.75,5); }
Simple Interest is 1537.500000 Simple Interest is 14687.500000
#include⁢stdio.h> void sum(int n) { int i,s=0; for(i=1;i<=n;i++) s=s+i; printf("sum is %d\n",s); } main() { sum(5); }
Sum is 15
#include⁢stdio.h> void factorial(int n) { int i,f=1; for (i=1;i<=n;i++) f=f*i; printf("factorial is %d\n",f); } main() { factorial(5); }
Factorial is 120