C++ Function Programs
C++ Function Programs
-------------
void area(float r)
{
float ar = 3.14 * r * r;
cout << "Area of circle: " << ar << endl;
}
float area(float r)
{
float ar = 3.14 * r * r;
return(ar);
}
3- Divisibility by 11
void main()
{
int a;
void div(int);
cout << "Enter the number: ";
cin >> a;
div(a);
}
void div(int a)
{
if (a % 11 == 0)
{
cout << "The given number is divisible by 11" << endl;
}
else
{
cout << "The given number is not divisible by 11" <<endl;
}
}
6- Eligibility to vote
void main()
{
int age;
void eligib(int);
cout<<"enter your age:";
cin>>age;
eligib(age);
}
void eligib(int a)
{
if(a>=18)
{
cout<<"you are eligible for voting:";
}
else
{
cout<<"you are noneligible for voting:";
cout<<"wait for"<<18-age<<"year(s):";
}
}
void series(int n)
{
int i;
cout << "The natural numbers upto "<<n<<"th terms are: \n";
for (i = 1; i <= n; i++)
{
cout << i << " ";
}
}
8- Table of a number
void main()
{
int n;
void table(int);
cout<<"Enter any number:";
cin>>n;
table(n);
}
void table(int n)
{
int i;
for(i=1;i<=10;++i)
{
cout<<"\n"<<n<<" * "<<i<<" = "<<n*i;
}
}
9- Star Pattern
void main()
{
void star(void);
star();
}
void star()
{
int i,j;
for(i=1;i<=5;++i)
{
for(j=1;j<=i;++j)
{
cout<<" * ";
}
cout<<�\n�;
}
}
void daynumber(int n)
{
switch(n)
{
case 1: cout<<"Monday";
break;
case 2: cout<<"Tuesday";
break;
case 3: cout<<"Wednesday";
break;
case 4: cout<<"Thursday";
break;
case 5: cout<<"Friday";
break;
case 6: cout<<"Saturday";
break;
case 7: cout<<"Sunday";
break;
default: cout<<"Invalid input! Please enter week no.between 1-7.";
}
}