C Language Tutorial Home

# Function Examples (Pass and Return)

#### Current Set : Set 7Set 1Set 2Set 3Set 4Set 5Set 6Set 7Set 8Set 9Set 10

Question:3
Write a function C language to take input for a numbers calculate and print its factorial?
Sol:

```#include <stdio.h>

//function definition
int fact(int n)
{
int i,f=1;
for(i=1;i<=n;i++)
{
f=f*i;
}
return(f);
}
int main()
{
int a,b;
printf("Enter any no ");
scanf("%d",&a);
b=fact(a);
printf("factorial = %d",b);
return 0;
}```

Question:4
Write a function C language to take input for 3 numbers check and print the largest number?
Sol:

```#include <stdio.h>

//function definition
int largest(int p,int q,int r)
{
int m;
if(p>q && p>r)
m=p;
else
if(q>r)
m=q;
else
m=r;
return(m);
}
/* 2nd method */
/*
int largest(int p,int q,int r)
{
if(p>q && p>r)
return(p);
else
if(q>r)
return(q);
else
return(r);
}
*/
int main()
{
int a,b,c,ma;
printf("Enter 3 nos ");
scanf("%d %d %d",&a,&b,&c);
ma=largest(a,b,c);
printf("largest no = %d",ma);
return 0;
}```

Important Pages