C Chapters

C program to compute sum of two integers using user defined function.

Types of Functions - Functions
/* User defined function in c Language */

#include<stdio.h>

int addNumbers(int a, int b);         // function prototype

int main()
{
    int n1,n2,sum;

    printf("Enters two numbers: ");
    scanf("%d %d",&n1,&n2);
    sum = addNumbers(n1, n2);        // function call
    printf("\nsum = %d",sum);

    return 0;
}

int addNumbers(int a,int b)         // function definition   
{
    int result;
    result = a+b;
    return result;                  // return statement
}

Output :
Enters two numbers: 4 4
sum = 8

Leave a comment
Recent Comments
  • Farrukh Kamran at 17-06-2018 08:21:00 AM
    Q1) Write a program to calculate percentage of five subjects by taking user input by use
    of UDF ?
    Q2) Write a program to calculate cube of any number By using UDF?