Example : Using function with arguments

#include <iostream.h>
#include <conio.h>
int add(int, int ); // prototype declaration
void main( )
{
int a,b,c;
clrscr( );
cout<<”Enter two numbers\n”;
cin>>a>>b;
c=add(a,b);
cout<<”Ans = “<<c<<”\n”;
getch();
}
int add(int x, int y )
{
int z;
z = x + y;
return(z);
}
Output :
Enter two numbers
10 20
Ans = 30

0 comments: