write a program to perform the following operations by using function overloading concept.
a. generate () : to use the function with an integer type argument to generate fibonacci series up to given value .
b. generated (): to use the function with two integer typ3 arguments to print the prime numbers between both the values
Answers
Answered by
0
Conceptual design based on ideas. Technical design based on knowledgeable and solid experience.
Answered by
0
Program in C++
#include<iostream>
using namespace std;
void generate(int n)
{
int a = 0, b = 1;
for (int i = 1; i <= n; ++i)
{
cout<<a<<" ";
int t = a + b;
a = b;
b = t;
}
}
void generate(int a , int b)
{
for(int i = a ; i <= b ; i++)
{
int count = 0;
for(int j = 1 ; j <= i ; j++)
{
if(i % j == 0)
{
count++;
}
}
if(count == 2)
{
cout<<i<<" ";
}
}
}
int main()
{
int a , b , c;
cout<<"Enter a number to generate fibonacci series : ";
cin>>a;
generate(a);
cout<<"\nEnter the lower limit : ";
cin>>b;
cout<<"Enter the upper limit : ";
cin>>c;
generate(b , c);
return 0;
}
Similar questions