Example program for functions in C C++ Sum of two numbers using function

Example program for functions in C C++ Sum of two numbers using function

Function क्या है इसका प्रयोग क्यो किया जाता है यह कितने प्रकार का होता है जानने के लिए देखें—Functions in C

Function में call by value और call by reference क्या होता है जानने के लिए देखें—Call by value and reference

C-Language में function recursion किसे कहते है और इसकी क्या उपयोगिता है जानने के लिए देखें— Recursion in C

Example program for functions in C

#include<stdio.h>
int sum(int,int);
int main()
{
    int a,b;
    printf("Enter two numbers: ");
    scanf("%d%d",&a,&b);
    printf("Sum of numbers = %d",sum(a,b));
    return 0;
}
int sum(int x, int y)
{
    return x+y;
}

Example program for functions in C++

#include<iostream>
using namespace std;
int sum(int,int);
int main()
{
    int a,b;
    cout<<"Enter two numbers: ";
    cin>>a>>b;
    cout<<"Sum of numbers = "<<sum(a,b);
    return 0;
}
int sum(int x, int y)
{
    return x+y;
}

Output of Example program for functions in C C++

Example program for functions in C C++

Related function example programs in C C++

  1. Average of three numbers using function
  2. Swapping using function call by value
  3. Swapping using function call by reference
  4. Passing array as function argument
  5. Passing structure as function argument
  6. Pointer to Function
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer