الدوال Functions

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

/

Functions

C++ .

:
-1 .
-2 .
-3 .
-4 .
-5 .
-6 function
function

.

:
)Return-type function-name (parameters-list
{
)(Body of function
;statement1
;statement2
:
;Statement-n
)(Return something
}

:
-1 (. ) string, long charfloat int
-2 return ). return(x
-3 ). x=sum(y,z
-4 )x=sum(y,z

.
)int max (int a, int b
{
;int c
;if (a > b) c = a
;else c = b
;)return (c
}

( ):

:
-1 . Void
-2 return Cout .
-3 ). sum(y,z
-4 .
)void max (int a, int b
{
;int c
)if (a > b
;c = a
else
;c = b
;cout << c
}
:
-1
-2
2


# include <iostream.h>
Void square (int n)
{
Int value;
Value=n*n;
Cout<<"i="<<n<<"square="<<value<<endl;
}
main ()
{
Int max;
Cout<<"Enter a value for n ?\n";
Cin>>max;
For (int i=0; i<=max-1; ++i)
Square (i)
}

# include <iostream.h>
Int square (int n)
{
Int value;
Value=n*n;
Return (value);
}
main ()
{
Int max;
Cout<<"Enter a value for n? \n";
Cin>>max;
For (int i=0; i<=max-1; ++i)
Value=square (i);
Cout<<"i="<<i<<:"square="<<value<<endl;
}


#include<iostream>
void swap(int a,int b)
{
Int temp;
temp=a;
a=b;
b=temp;
cout<<"a="<<a<<endl;
cout<<"b="<<b;
}
Main ()
{
Int x=4, x=7;
Int x1,y1;
Cin >>x1>>y1;
Cout<<"Before Swap:";

Cout<<"x="<<x<<"y="<<y<<endl;
Cout<<"x1="<<x1<<"y1="<<y1<<endl;
cout<<"After Swap:"<<endl;
swap(x,y);
swap(x1,y1);
}
3


>#include<iostream.h
)int sum(int a,int b
{
;Int res
;res=a+b
;)return(res
}
)Int sub(int a,int b
{
;Int res
;res=a-b
;)return(res
}
)Int mul(int a,int b
{
;Int res
;res=a*b
;)return(res
}
)(main
{
;int a,b,m,su,s
;cout<<Enter two numbers:
;cin>>a>>b
;)s=sum (a,b
;)su=sub(a,b
;)m=mul(a,b
;Cout<<"Sum :"<< s<<"Subtraction :"<< su<<"Multiplication :"<< m
}
:
-1
-2

You might also like