Function
Function
Prof. A.P.Khan
Department of Computer Engineering
D.N.Patel College of Engineering, Shahada
Function
8
Function without argument and with return value.
#include<iostream.h>
int sum();
void main()
{
int result;
cout"\nGoing to calculate the sum of two numbers:";
result = sum();
cout<<result;
}
int sum()
{
int a,b;
cout<<"\nEnter two numbers";
cin>>a>>b;
return a+b;
} 9
#include<stdio.h>
int even_odd(int); }
void main() int even_odd(int n)
{ {
int n,flag=0; if(n%2 == 0)
cout<<“\nGoing to check whether a number is even or odd"; {
cout<<"\nEnter the number: ”; return 1;
cin>>n; }
flag = even_odd(n); else
if(flag == 0) {
{ return 0;
cout<<“\nThe number is odd"; }
} }
else
{
cout<<“The number is even";
}
10
THANKS!
Any questions?
+91-9893092930
er.ashfaqkhan@gmail.com
11