Function2022 Examples
Function2022 Examples
{
float num;
cout<<"plz enter the
grade of the student";
cin>>num;
fgrde(num);
}
1
DR Albert Shawky
2
DR Albert Shawky
# include <iostream>
using namespace std;
if(oper=='+')
result=num1+num2;
else if (oper=='-')
result=num1-num2;
else if (oper=='*')
result=num1*num2;
else if (oper=='/')
result=num1/num2;
else
cout<<"invalibleinput oper";
cout<<"result"<<result<<endl;
}
void main()
{
double num1,num2;
char oper;
calc(num1,num2,oper);
system("pause");}
if(oper=='+')
result=num1+num2;
else if (oper=='-')
result=num1-num2;
else if (oper=='*')
result=num1*num2;
else if (oper=='/')
result=num1/num2;
else
cout<<"invalibleinput oper";
return (result);
}
void main()
{
double num1,num2;
char oper;
double m = calc(num1,num2,oper);
cout<<”the result is “<<m;
system("pause");}
4
DR Albert Shawky
#include <iostream>
using namespace std;
void main ()
{
int f=1,a;
cout<<"Please enter num";
cin>>a;
for(int i=a;i>=1;i--)
{
f*=i;
}
cout<<"factorial="<<f;
system("pause");
}
# include <iostream> # include <iostream>
using namespace std; using namespace std;
} }
Void main() Void main()
{ {
int num; int num;
cout<<"plz enter the cout<<"plz enter the
number "; number";
cin>>num; cin>>num;
factorial (num);
int z= factorial (num);
cout<<z;
} 5
}
DR Albert Shawky
30. Write a function named "sum" that takes as its arguments the following:
(1) an array of floating point values;
(2) an integer that tells how many floating point values are in the array.
The function should return as its value the sum of the floating point values in the
array. Thus, for example, if the
array that's passed to the function looks like this:
Void main()
{
float x[5];
cout<<”please enter values”;
Float z= sum(x,5);
cout<<”sum=”<<z;
6
DR Albert Shawky
7
DR Albert Shawky