Example program for functions in C C++

 

Coding 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;
}

 

Coding 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

Example program for functions in C C++

 

Published by

admin

I am a computer teacher, programmer and web developer