Functions in c

Preview:

Citation preview

Functions in C Language

main()

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

main()

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

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

main()

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

main()

1

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

main()

1x

y

x is actual argument

y is formal argument2

y

x 5

5

voidintfloat

#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;

}

#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

#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;

}

#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;

}

Factorial value

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

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

#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

Recommended