With Arguments and With Return Values Function in C

This “With Arguments and With Return Values Function” page providing clear examples to write and understand above classification.


 

With arguments and With return values :

  • Function is taking arguments(input values) and return output.
  • Input values are working like local variables.
  • output data variables also can be a local variable.
  • Based on input and output variables, we can find out the memory size of a function.

 

#include<stdio.h>
int add(int,int);
void main(void)
{
int a,b,c;
printf(“Enter two numbers\n”);
scanf(“%d%d”,&a,&b);
c = add(a,b);
printf(“sum : %d\n”,c);
}
int add(int x, int y)
{
int z;
z=x+y;
return z;
}
‚Äč

Program to check input number is Perfect Number or Not
#include<stdio.h>
int isPerfect(int);
void main(void)
{
int n,res;
printf(“Enter n value : \n”);
scanf(“%d”,&n);
res = isPerfect(n);
if(res)
printf(“Perfect Number \n”);
else
printf(“Not a Perfect Number \n”);
}
int isPerfect(int x)
{
int i, sum=0;
for(i=1 ; i<x ; i++)
{
if(x%i==0)
{
sum+=i;
}
}
if(sum==x)
return 1 ;
else
return 0 ;
}

Share this