User-Defined Function in C

Get Certified in C Programming and Take Your Skills to the Next Level

Program 1

// Program for user define function
#include<stdio.h>
#include<conio.h>
#include<string.h>

int addition(int ,int);  // declare

int main()
{
    system("cls");
    int x,y,z;
    printf("Enter two number");
    scanf("%d%d",&x,&y);
     z=addition(x,y);  //calling    call by value 
     printf("Addition is %d",z);
    return 0;
}
int addition(int a,int b)  // defination
{
      int c;
      c=a+b;
     return(c);
}

Program 2

// Program for user define function
#include<stdio.h>
#include<conio.h>
#include<string.h>

 int factorial(int); // declare

int main()
{
     int x;
     system("cls");
     x=factorial(5);
     printf("Factorial is %d: ",x); 
     return 0;
}
int factorial(int n)
{
    int f=1;
    while(n!=0)
    {
        f=f*n;
        n--;
    }
    return(f);

}

 

Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google

courses
Image

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *